Unit 11: Inference for Categorical Data: Chi-Square
Test distributions of categorical data: chi-square goodness of fit, homogeneity and independence, expected counts, conditions and conclusions.
单元 11:分类数据的推断:卡方检验
检验分类数据的分布:卡方拟合优度检验、同质性检验与独立性检验、期望频数、适用条件与结论。
Each topic gives objectives, an explanation, worked examples, an exam tip, common mistakes and check questions with answers. Use the contents list to jump to a topic, then finish with the unit quiz. All data are synthetic illustrations.
每个主题含学习目标、讲解、例题、考试提示、常见错误与带答案的自测题。可用目录跳转到任一主题,最后完成单元自测。所有数据均为合成示例。
The chi-square statistic and distribution卡方统计量与卡方分布
- Compute the chi-square statistic $\chi^2=\sum\frac{(O-E)^2}{E}$ from observed and expected counts.
- Explain why each difference is squared and divided by the expected count, and why $\chi^2$ is never negative.
- Describe the chi-square distribution: right-skewed, set by its degrees of freedom, with mean equal to the degrees of freedom.
- Find a right-tail p-value with the chi-square cdf and say what it measures.
- 由观测计数与期望计数计算卡方统计量 $\chi^2=\sum\frac{(O-E)^2}{E}$。
- 说明为什么每个差要平方并除以期望计数,以及 $\chi^2$ 为什么不会为负。
- 描述卡方分布:右偏,由自由度决定,均值等于自由度。
- 用卡方累积分布函数求右尾 p 值,并说明它度量什么。
Many AP Statistics questions are about categorical data in counts. A chi-square procedure asks one question: how far are the observed counts from the expected counts we would see if a claim (the null hypothesis) were true? The answer is a single number, the chi-square statistic: $$\chi^2=\sum\frac{(O-E)^2}{E}$$ where $O$ is an observed count, $E$ is the expected count for the same category or cell, and the sum of these terms runs over every category (or every cell of a table). Expected counts are always computed assuming the null hypothesis is true.
许多 AP 统计学问题涉及以计数表示的分类数据。卡方过程只问一个问题:如果某个说法(原假设)成立,我们应看到的期望计数与实际观测计数相差多远?答案是一个数,即卡方统计量:$$\chi^2=\sum\frac{(O-E)^2}{E}$$ 其中 $O$ 是观测计数,$E$ 是同一类别(或单元格)的期望计数,对所有类别(或表中所有单元格)求和。期望计数总是在假设原假设成立的前提下计算。
Each piece of the formula has a job. Observed and expected counts both add to the same total, so the raw differences $O-E$ always sum to zero; squaring stops positive and negative differences from cancelling. Dividing by $E$ puts differences on a fair scale: being 10 over matters a lot when you expected 20 but hardly at all when you expected 2000. Each term is that category's contribution to $\chi^2$. The statistic equals $0$ only when every observed count equals its expected count, and the farther the counts drift from expectation, the larger it gets. Sample size matters too: if every observed count is multiplied by the same factor $c$ while the proportions stay the same, every expected count is multiplied by $c$ as well, and $\frac{(cO-cE)^2}{cE}=c\,\frac{(O-E)^2}{E}$, so the chi-square statistic is multiplied by $c$. The same pattern in a larger sample therefore gives stronger evidence.
公式的每一部分都有作用。观测计数与期望计数的总和相同,所以原始差 $O-E$ 的总和恒为零;平方避免正负差互相抵消;除以 $E$ 让差值有公平的尺度:期望 20 却多出 10 影响很大,期望 2000 时则几乎无关紧要。每一项是该类别对 $\chi^2$ 的贡献。只有每个观测计数都等于期望计数时统计量才为 $0$,计数偏离期望越远,统计量越大。样本量也有影响:如果每个观测计数都乘以同一个因子 $c$,而比例不变,那么每个期望计数也乘以 $c$,并且 $\frac{(cO-cE)^2}{cE}=c\,\frac{(O-E)^2}{E}$,所以卡方统计量变为原来的 $c$ 倍。因此同样的模式出现在更大的样本中,会给出更强的证据。
$\chi^2\ge 0$ always. A large $\chi^2$ is evidence against the null hypothesis, and the p-value is the area to the right of the observed $\chi^2$ under the chi-square curve. There is no left tail and no two-sided version for these tests, and counts (not percentages) go into the formula.
$\chi^2\ge 0$ 恒成立。$\chi^2$ 大说明有证据反对原假设,p 值是卡方曲线下观测 $\chi^2$ 右侧的面积。这类检验没有左尾,也没有双侧版本,公式中代入的是计数(而不是百分比)。
The chi-square distribution卡方分布
Chi-square distributions are continuous curves defined only for values at or above $0$. Each one is right-skewed, and its exact shape is set by one number, the degrees of freedom (df). With small df the curve is strongly skewed and piles up near $0$; as df grows the curve moves to the right, flattens and becomes more symmetric. The mean of a chi-square distribution equals its df, so a statistic close to the df is typical when the null hypothesis is true, and one far above it is surprising. Figure 8.1 shows three of these curves.
卡方分布是只在 $0$ 及以上取值的连续曲线。每条曲线都是右偏的,具体形状由一个数,即自由度(df)决定。自由度小时曲线强烈右偏并集中在 $0$ 附近;自由度增大后曲线右移、变平、更接近对称。卡方分布的均值等于它的自由度,所以原假设成立时,接近自由度的统计量是典型的,远高于自由度的统计量则令人意外。图 8.1 给出三条这样的曲线。
To get a p-value, find the area to the right of the observed statistic. On a TI-84 use the chi-square cdf from the DISTR menu, χ²cdf(lower, upper, df), with a very large upper bound: p-value $=$ χ²cdf($\chi^2$, 1E99, df). A table of critical values works too: for $\alpha=0.05$ the critical values are $5.991$ (df $2$), $7.815$ (df $3$), $9.488$ (df $4$) and $11.070$ (df $5$), so a statistic below the critical value for its df has a p-value above $0.05$.
求 p 值就是求观测统计量右侧的面积。TI-84 上使用 DISTR 菜单中的卡方累积分布函数 χ²cdf(下限, 上限, df),上限取一个很大的数:p 值 $=$ χ²cdf($\chi^2$, 1E99, df)。也可以查临界值表:$\alpha=0.05$ 时,临界值为 $5.991$(df $2$)、$7.815$(df $3$)、$9.488$(df $4$)、$11.070$(df $5$),所以统计量低于其自由度对应的临界值时,p 值大于 $0.05$。
Worked Example 8.1: compute the statistic, df and p-value from counts例题 8.1:由计数计算统计量、自由度与 p 值
A school cafeteria offers four entrées and a manager wonders whether students choose them equally often. A random sample of $100$ students picks: $18$, $22$, $30$ and $30$. If demand were equal, the expected count is $25$ for each entrée. (All data here are illustrative.)
- Contributions: $\frac{(18-25)^2}{25}=1.96$, $\frac{(22-25)^2}{25}=0.36$, $\frac{(30-25)^2}{25}=1.00$, and $1.00$ again for the last entrée.
- Add them: $\chi^2=1.96+0.36+1.00+1.00=4.32$.
- Degrees of freedom: $4$ entrées gives $\text{df}=4-1=3$.
- p-value:
χ²cdf($4.32$, 1E99, $3$) $=0.2289$. - Interpretation: the statistic $4.32$ is only a little above the mean of $3$ for this distribution. If demand really were equal, about $23\%$ of random samples would drift at least this far from equal by chance alone, so this is not unusual.
某学校食堂提供四种主菜,经理想知道学生选择它们的频率是否相同。随机抽取 $100$ 名学生,选择人数分别为 $18$、$22$、$30$、$30$。若需求相同,每种主菜的期望计数都是 $25$。(本例数据均为虚构示例。)
- 各项贡献:$\frac{(18-25)^2}{25}=1.96$,$\frac{(22-25)^2}{25}=0.36$,$\frac{(30-25)^2}{25}=1.00$,最后一种主菜同样为 $1.00$。
- 相加:$\chi^2=1.96+0.36+1.00+1.00=4.32$。
- 自由度:$4$ 种主菜,$\text{df}=4-1=3$。
- p 值:
χ²cdf($4.32$, 1E99, $3$) $=0.2289$。 - 解释:统计量 $4.32$ 只略高于该分布的均值 $3$。若需求确实相同,约 $23\%$ 的随机样本仅凭偶然就会偏离到这种程度,所以这并不异常。
Worked Example 8.2: the same statistic with different degrees of freedom例题 8.2:同一统计量,不同自由度
A statistic of $\chi^2=10.4$ is reported. Find the p-value when (a) $\text{df}=5$ and (b) $\text{df}=2$.
- (a)
χ²cdf($10.4$, 1E99, $5$) $=0.0647$. This agrees with the table: $10.4<11.070$, the critical value for $\text{df}=5$, so the p-value exceeds $0.05$. - (b)
χ²cdf($10.4$, 1E99, $2$) $=0.0055$. Now $10.4>5.991$, so the p-value is below $0.05$. - The same number is ordinary for a curve with a larger mean and extreme for one with a smaller mean. Always report df beside $\chi^2$.
某检验报告的统计量为 $\chi^2=10.4$。分别求 (a) $\text{df}=5$ 和 (b) $\text{df}=2$ 时的 p 值。
- (a)
χ²cdf($10.4$, 1E99, $5$) $=0.0647$。与查表一致:$10.4<11.070$($\text{df}=5$ 的临界值),所以 p 值大于 $0.05$。 - (b)
χ²cdf($10.4$, 1E99, $2$) $=0.0055$。此时 $10.4>5.991$,所以 p 值小于 $0.05$。 - 同一个数值,对均值较大的曲线是普通的,对均值较小的曲线则是极端的。报告 $\chi^2$ 时务必同时给出自由度。
Judging a statistic against its degrees of freedom对照自由度判断统计量的大小
The center and spread of a chi-square distribution are both set by the degrees of freedom: the mean is $\text{df}$ and the standard deviation is $\sqrt{2\,\text{df}}$. For $\text{df}=3$ that is a mean of $3$ and a standard deviation of about $2.45$, so a statistic of $4.32$ sits less than one standard deviation above the mean, while a statistic of $8.9$ sits more than two standard deviations above it. Use this only as a sanity check on your arithmetic, because the curve is skewed and the decision always comes from the p-value or a table, never from counting standard deviations. A good habit is to say before computing whether you expect a large or a small p-value, and then to check that the answer agrees. If every category is close to its expected count, $\chi^2$ should land near or below the df; a statistic several times the df can only come from counts far from expectation.
卡方分布的中心和离散程度都由自由度决定:均值是 $\text{df}$,标准差是 $\sqrt{2\,\text{df}}$。$\text{df}=3$ 时均值为 $3$,标准差约为 $2.45$,所以统计量 $4.32$ 比均值高出不到一个标准差,而统计量 $8.9$ 则比均值高出两个多标准差。这只能用来检查计算是否合理:曲线是偏斜的,判断永远来自 p 值或查表,而不是数标准差。好习惯是先说出你预期 p 值大还是小,算完再核对是否一致。如果每个类别都接近其期望计数,$\chi^2$ 应该接近或低于自由度;统计量是自由度的好几倍,只可能来自与期望相差很远的计数。
When no calculator is available, bracket the p-value with a table of critical values. For $\text{df}=3$ the right-tail areas $0.05$, $0.025$ and $0.01$ correspond to the critical values $7.815$, $9.348$ and $11.345$. A statistic that falls between two critical values has a p-value between the two matching areas. The table gives a range and the calculator gives the exact value; a written answer may use either, as long as the conclusion follows from what is shown.
没有计算器时,可以用临界值表给 p 值定范围。$\text{df}=3$ 时,右尾面积 $0.05$、$0.025$、$0.01$ 对应的临界值分别是 $7.815$、$9.348$、$11.345$。统计量落在两个临界值之间,p 值就落在对应的两个面积之间。表给出的是一个范围,计算器给出的是精确值;书面作答用哪个都可以,只要结论能从所写内容推出。
Worked Example: doubling the sample with the same percentages例题:样本量加倍而百分比不变
This example practises bracketing the p-value with a table and shows how sample size changes the evidence. The cafeteria manager in Worked Example 8.1 doubles the sample to $200$ students. The counts are $36$, $44$, $60$ and $60$, the same percentages as before. Test whether the four entrées are chosen equally often, at $\alpha=0.05$. (Illustrative data.)
- Equal demand gives expected counts $\frac{200}{4}=50$ for every entrée, all at least $5$.
- Contributions: $\frac{(36-50)^2}{50}=3.92$, $\frac{(44-50)^2}{50}=0.72$, $\frac{(60-50)^2}{50}=2.00$ and $2.00$.
- $\chi^2=3.92+0.72+2.00+2.00=8.64$, which is exactly twice the earlier $4.32$, and $\text{df}=4-1=3$.
- Bracket with the table: $7.815<8.64<9.348$, so the p-value lies between $0.025$ and $0.05$. The calculator gives
χ²cdf($8.64$, 1E99, $3$) $=0.0345$. - A complete answer states: because $0.0345<0.05$, reject $H_0$; there is convincing evidence that the four entrées are not chosen equally often by students at this school.
- Compare with the sample of $100$: the same percentages gave a p-value of $0.2289$ and no evidence. More data with the same pattern is stronger evidence, which is why the statistic doubled while the df stayed at $3$.
本例练习用表给 p 值定范围,并说明样本量如何改变证据强度。例题 8.1 中的食堂经理把样本加倍到 $200$ 名学生,计数为 $36$、$44$、$60$、$60$,百分比与之前相同。在 $\alpha=0.05$ 下检验四种主菜被选择的频率是否相同。(虚构数据。)
- 需求相同时,每种主菜的期望计数为 $\frac{200}{4}=50$,都不小于 $5$。
- 各项贡献:$\frac{(36-50)^2}{50}=3.92$,$\frac{(44-50)^2}{50}=0.72$,$\frac{(60-50)^2}{50}=2.00$,另一项也是 $2.00$。
- $\chi^2=3.92+0.72+2.00+2.00=8.64$,恰好是之前 $4.32$ 的两倍,$\text{df}=4-1=3$。
- 用表给范围:$7.815<8.64<9.348$,所以 p 值在 $0.025$ 与 $0.05$ 之间。计算器给出
χ²cdf($8.64$, 1E99, $3$) $=0.0345$。 - 完整答案要点:因为 $0.0345<0.05$,拒绝 $H_0$;有令人信服的证据表明该校学生选择四种主菜的频率并不相同。
- 对比样本量为 $100$ 的情形:同样的百分比得到 p 值 $0.2289$,没有证据。同样的模式配上更多数据就是更强的证据,所以统计量翻了一倍,而自由度仍为 $3$。
A student finds $\chi^2=12.0$ with $\text{df}=4$ and enters χ²cdf($0$, $12$, $4$), which returns $0.9826$, then writes 'not significant'. That number is the area to the left of $12.0$, so it says the statistic is large, not small. Another student gets the right tail, $0.0174$, and doubles it to $0.0347$ 'to be safe'. Both moves are wrong for a chi-square test. The fix: set the lower bound to the statistic and the upper bound to 1E99, χ²cdf($12$, 1E99, $4$) $=0.0174$, and never double it. Since $0.0174<0.05$, this is convincing evidence against $H_0$.
某学生算出 $\chi^2=12.0$、$\text{df}=4$,输入 χ²cdf($0$, $12$, $4$),得到 $0.9826$,就写下“不显著”。这个数是 $12.0$ 左侧的面积,恰恰说明统计量很大而不是很小。另一位学生得到了正确的右尾 $0.0174$,却“为保险起见”乘 2 变成 $0.0347$。对卡方检验,这两种做法都是错的。正确做法:下限取统计量,上限取 1E99,χ²cdf($12$, 1E99, $4$) $=0.0174$,并且绝不加倍。因为 $0.0174<0.05$,这是反对 $H_0$ 的令人信服的证据。
A chi-square p-value is always a right-tail area, so never double it and never use a left tail. When you show work, write the formula with the actual counts substituted, for example $\frac{(18-25)^2}{25}$, and always state the degrees of freedom beside the statistic.
卡方检验的 p 值永远是右尾面积,不要加倍,也不要用左尾。写过程时,把实际计数代入公式,例如 $\frac{(18-25)^2}{25}$,并始终在统计量旁写出自由度。
- Leaving out the square, or dividing by $O$ instead of $E$.
- Putting percentages or proportions into the formula instead of counts.
- Reporting a statistic without its degrees of freedom, or finding the p-value with the wrong df.
- 漏掉平方,或除以 $O$ 而不是 $E$。
- 把百分比或比例而不是计数代入公式。
- 报告统计量时不写自由度,或用错误的自由度求 p 值。
Can $\chi^2$ be negative? Explain.$\chi^2$ 能为负吗?请说明。
No. Every term is $\frac{(O-E)^2}{E}$ with a square on top and a positive expected count underneath, so each term is at least $0$ and so is their sum.
不能。每一项 $\frac{(O-E)^2}{E}$ 分子是平方、分母是正的期望计数,所以每项不小于 $0$,总和也是非负的。
A test has $\text{df}=4$ and $\chi^2=4.2$. Without calculating, is this strong evidence against the null hypothesis?某检验 $\text{df}=4$,$\chi^2=4.2$。不计算的话,这是反对原假设的有力证据吗?
No. The mean of a chi-square distribution equals its df, which is $4$, so $4.2$ is typical. The p-value is large (it is about $0.38$).
不是。卡方分布的均值等于自由度,即 $4$,所以 $4.2$ 是典型值。p 值很大(约 $0.38$)。
Find the contribution to $\chi^2$ for a category with $O=12$, $E=8$, and for one with $O=4$, $E=8$. What do you notice?分别求下列两个类别对 $\chi^2$ 的贡献:$O=12$、$E=8$ 的类别,以及 $O=4$、$E=8$ 的类别。你注意到什么?
Both give $\frac{(\pm 4)^2}{8}=2.0$. Squaring makes being too high and too low count the same; the chi-square statistic does not record direction.
两者都是 $\frac{(\pm 4)^2}{8}=2.0$。平方使偏高与偏低同样计数;卡方统计量不记录方向。
Goodness of fit: hypotheses and conditions拟合优度:假设与条件
- Recognize a goodness-of-fit situation: one sample, one categorical variable, a claimed distribution.
- Write the null and alternative hypotheses in context.
- Compute expected counts $E=np$ from the claimed proportions.
- Check the conditions (random, 10%, all expected counts at least 5) and state the degrees of freedom $k-1$.
- 识别拟合优度情境:一个样本、一个分类变量、一个给定的分布。
- 结合情境写出原假设与备择假设。
- 由给定比例计算期望计数 $E=np$。
- 检验条件(随机、10%、所有期望计数至少为 5)并写出自由度 $k-1$。
A chi-square goodness-of-fit test asks whether the distribution of one categorical variable in a population matches a claimed distribution. The data are one random sample, each individual is placed in exactly one of $k$ categories, and the claim gives a proportion $p_1,p_2,\dots,p_k$ for every category (the proportions add to $1$).
卡方拟合优度检验用于判断总体中一个分类变量的分布是否与给定的分布相符。数据是一个随机样本,每个个体恰好属于 $k$ 个类别之一,给定的说法为每个类别指定比例 $p_1,p_2,\dots,p_k$(比例之和为 $1$)。
The null hypothesis says the population proportions equal the claimed ones. The alternative hypothesis says at least one proportion differs; it is never directional and it does not say that every proportion differs. Write both in context, naming the population and the variable. In symbols, $H_0$: $p_i$ equals its claimed value for every category $i$, and $H_a$: at least one $p_i$ differs from its claimed value.
原假设说总体比例等于给定的比例,备择假设说至少有一个比例不同;它没有方向,也不是说每个比例都不同。两者都要结合情境,写明总体与变量。用符号表示:$H_0$:$p_i$ 等于其给定值,对每个类别 $i$ 都成立;$H_a$:至少有一个 $p_i$ 与其给定值不同。
The expected count for category $i$ is $E_i=np_i$: the sample size times the claimed proportion (not the sample's proportion). Expected counts need not be whole numbers, and they add to $n$.
类别 $i$ 的期望计数为 $E_i=np_i$:样本量乘以给定的比例(不是样本比例)。期望计数不必是整数,且总和为 $n$。
| Condition | How to check | Why it matters |
|---|---|---|
| Random | The data come from a random sample (or a randomized process) | Lets the sample stand in for the population |
| 10% | When sampling without replacement, $n$ is less than $10\%$ of the population | Keeps the observations close to independent |
| Large counts | Every expected count $np_i\ge 5$ (check expected, not observed) | The chi-square curve is a good model for the statistic |
| 条件 | 如何检验 | 为什么重要 |
|---|---|---|
| 随机 | 数据来自随机样本(或随机化过程) | 使样本能代表总体 |
| 10% | 不放回抽样时,$n$ 小于总体的 $10\%$ | 使各观测近似独立 |
| 大计数 | 每个期望计数 $np_i\ge 5$(检查期望计数,不是观测计数) | 卡方曲线才能很好地近似该统计量的分布 |
The degrees of freedom for goodness of fit are $\text{df}=k-1$, the number of categories minus one: once $k-1$ category counts are known, the last is fixed by the total $n$. It is not $n-1$.
拟合优度检验的自由度为 $\text{df}=k-1$,即类别数减一:已知 $k-1$ 个类别的计数后,最后一个由总数 $n$ 确定。它不是 $n-1$。
Worked Example 8.3: hypotheses, expected counts and conditions例题 8.3:假设、期望计数与条件
A company claims its trail mix is $40\%$ peanuts, $30\%$ raisins, $20\%$ candy pieces and $10\%$ cereal. An analyst takes a random sample of $200$ pieces from one day's production (far more than $2000$ pieces) and records each piece's type. (Illustrative scenario.)
- Hypotheses. $H_0$: the distribution of piece type in this day's production is as claimed, $p_1=0.40$, $p_2=0.30$, $p_3=0.20$, $p_4=0.10$. $H_a$: at least one of these proportions is different from the claimed value.
- Expected counts. $E=200(0.40)=80$, $200(0.30)=60$, $200(0.20)=40$, $200(0.10)=20$; they add to $200$.
- Conditions. Random: the analyst took a random sample. 10%: $200$ is less than $10\%$ of the day's output, which is more than $2000$ pieces. Large counts: the smallest expected count is $20$, which is at least $5$.
- Degrees of freedom. There are $k=4$ categories, so $\text{df}=4-1=3$.
某公司声称其什锦坚果由 $40\%$ 花生、$30\%$ 葡萄干、$20\%$ 糖果块和 $10\%$ 谷物组成。分析员从某天的产品中随机抽取 $200$ 块(该天产量远超 $2000$ 块),记录每块的类型。(虚构情境。)
- 假设。$H_0$:该天产品中各类型的分布与声称一致,$p_1=0.40$,$p_2=0.30$,$p_3=0.20$,$p_4=0.10$。$H_a$:这些比例中至少有一个与声称值不同。
- 期望计数。$E=200(0.40)=80$,$200(0.30)=60$,$200(0.20)=40$,$200(0.10)=20$;总和为 $200$。
- 条件。随机:分析员抽取的是随机样本。10%:$200$ 小于该天产量的 $10\%$,而产量超过 $2000$ 块。大计数:最小的期望计数是 $20$,不小于 $5$。
- 自由度。共有 $k=4$ 个类别,所以 $\text{df}=4-1=3$。
Worked Example 8.4: when the large-counts condition fails例题 8.4:大计数条件不满足时
A different claim lists five categories with proportions $0.40$, $0.30$, $0.20$, $0.08$ and $0.02$, and the random sample has $n=60$. (Illustrative scenario.)
- Expected counts: $60(0.40)=24$, $60(0.30)=18$, $60(0.20)=12$, $60(0.08)=4.8$, $60(0.02)=1.2$.
- Two expected counts are below $5$, so the large-counts condition fails and the chi-square test is not valid as set up.
- Fix 1: combine the last two categories into one sensible "other" category with proportion $0.10$. The expected counts become $24$, $18$, $12$, $6$, all at least $5$, and the new df is $4-1=3$. Decide to combine before looking at the results.
- Fix 2: take a larger sample. The smallest category needs $n(0.02)\ge 5$, so $n\ge 250$.
另一个说法列出五个类别,比例为 $0.40$、$0.30$、$0.20$、$0.08$、$0.02$,随机样本量 $n=60$。(虚构情境。)
- 期望计数:$60(0.40)=24$,$60(0.30)=18$,$60(0.20)=12$,$60(0.08)=4.8$,$60(0.02)=1.2$。
- 有两个期望计数小于 $5$,大计数条件不满足,按原设置卡方检验无效。
- 办法一:把最后两个类别合并为一个合理的“其他”类别,比例 $0.10$。期望计数变为 $24$、$18$、$12$、$6$,都不小于 $5$,新的自由度为 $4-1=3$。合并要在看结果之前决定。
- 办法二:增大样本量。最小的类别需要 $n(0.02)\ge 5$,即 $n\ge 250$。
Turning a claim into proportions把说法转换成比例
Claims come in different forms, and each must become a list of proportions that adds to $1$. A ratio such as $9:3:3:1$ has $9+3+3+1=16$ parts, so the proportions are $\frac{9}{16}$, $\frac{3}{16}$, $\frac{3}{16}$ and $\frac{1}{16}$. A table of percentages is divided by $100$. A claim of 'equally likely' gives $\frac1k$ to each of $k$ categories. When the claim lists only some of the categories, the leftover share belongs to an 'other' category that has to be added, so that every individual in the sample has a place and the proportions still add to $1$. Multiply each proportion by $n$ to get the expected counts, and check that they add to $n$.
说法有各种形式,每一种都要变成总和为 $1$ 的比例列表。比例 $9:3:3:1$ 共有 $9+3+3+1=16$ 份,所以各比例为 $\frac{9}{16}$、$\frac{3}{16}$、$\frac{3}{16}$、$\frac{1}{16}$。百分比表要除以 $100$。“可能性相等”的说法给 $k$ 个类别各 $\frac1k$。如果说法只列出了部分类别,剩下的份额属于必须补上的“其他”类别,这样样本中每个个体都有归属,比例之和仍为 $1$。把每个比例乘以 $n$ 得到期望计数,并检查它们的总和是 $n$。
Why the large-counts condition depends on the sample size为什么大计数条件取决于样本量
The condition $np_i\ge 5$ must hold for every category, so the category with the smallest claimed proportion is the first to fail. If the smallest claimed proportion is $0.10$, the sample needs at least $\frac{5}{0.10}=50$ individuals. When a planned sample is too small, the options are to collect more data, or to merge rare categories into a larger one when that still answers the question; the degrees of freedom then use the new number of categories. Deciding the categories before looking at the data keeps the test honest.
条件 $np_i\ge 5$ 必须对每个类别都成立,所以给定比例最小的类别最先不满足。若最小的给定比例是 $0.10$,样本至少需要 $\frac{5}{0.10}=50$ 个个体。计划的样本太小时,可以多收集数据,或者在仍能回答问题的前提下把稀少的类别并入较大的类别;此时自由度用新的类别数计算。在看数据之前就定好类别,检验才可靠。
Worked Example: state and plan a test when the claim leaves a share unlisted例题:说法没列出全部份额时,陈述并规划检验
A school says that $45\%$ of its students walk or bike to school, $30\%$ ride the bus and $15\%$ arrive by car, and the rest use other means. A student council member takes a random sample of $80$ students from a school with more than $800$ students and records each student's usual way of getting to school. Write the hypotheses and check the conditions for a goodness-of-fit test. (Illustrative.)
- The unlisted share is $1-0.45-0.30-0.15=0.10$, so there are $k=4$ categories: walk or bike, bus, car, other.
- $H_0$: the proportions of students at this school are $0.45$, $0.30$, $0.15$ and $0.10$ for walk or bike, bus, car and other. $H_a$: at least one of these proportions is different.
- Expected counts: $80(0.45)=36$, $80(0.30)=24$, $80(0.15)=12$ and $80(0.10)=8$. They add to $80$, and the smallest is $8\ge 5$.
- Random: the students were chosen at random. $10\%$: $80$ is less than $10\%$ of more than $800$ students. Large counts: all expected counts are at least $5$. So $\text{df}=4-1=3$ and the test can go ahead.
- Suppose the council could ask only $40$ students. Then the expected counts are $18$, $12$, $6$ and $4$, and $4<5$ fails the condition. Since $0.10\,n\ge 5$ needs $n\ge 50$, the sample must have at least $50$ students.
某学校称,$45\%$ 的学生步行或骑车上学,$30\%$ 乘公交,$15\%$ 乘私家车,其余用其他方式。学生会成员从一所超过 $800$ 名学生的学校中随机抽取 $80$ 名学生,记录每人通常的上学方式。请写出假设并检验拟合优度检验的条件。(虚构示例。)
- 未列出的份额是 $1-0.45-0.30-0.15=0.10$,所以共有 $k=4$ 个类别:步行或骑车、公交、私家车、其他。
- $H_0$:该校学生中步行或骑车、公交、私家车、其他的比例分别为 $0.45$、$0.30$、$0.15$、$0.10$。$H_a$:这些比例中至少有一个不同。
- 期望计数:$80(0.45)=36$,$80(0.30)=24$,$80(0.15)=12$,$80(0.10)=8$。它们的和是 $80$,最小的是 $8\ge 5$。
- 随机:学生是随机抽取的。$10\%$:$80$ 不到超过 $800$ 名学生的 $10\%$。大计数:所有期望计数都不小于 $5$。于是 $\text{df}=4-1=3$,检验可以进行。
- 假设学生会只能问 $40$ 名学生,期望计数变为 $18$、$12$、$6$、$4$,而 $4<5$,条件不满足。因为 $0.10\,n\ge 5$ 要求 $n\ge 50$,样本至少要有 $50$ 名学生。
A student reads the claim above, lists only walk or bike, bus and car, and computes expected counts $36$, $24$ and $12$ with $k=3$ and $\text{df}=2$. Those expected counts add to $72$, not $80$, so the $8$ students who use other means have no place in the table and the statistic is wrong. The fix is to add the fourth category 'other' with proportion $0.10$, expected count $8$, and use $k=4$ and $\text{df}=3$. A quick check is that the claimed proportions add to $1$ and the expected counts add to $n$.
某学生读了上面的说法,只列出步行或骑车、公交、私家车三类,算出期望计数 $36$、$24$、$12$,取 $k=3$、$\text{df}=2$。这些期望计数之和是 $72$ 而不是 $80$,用其他方式上学的 $8$ 名学生在表里没有位置,统计量因此是错的。正确做法是补上第四类“其他”,比例 $0.10$,期望计数 $8$,并取 $k=4$、$\text{df}=3$。快速检查:给定比例之和为 $1$,期望计数之和为 $n$。
Check the large-counts condition with the expected counts and show them, for example "expected counts are $80, 60, 40, 20$, all at least $5$". Checking the observed counts does not test the condition. Write the hypotheses in context: say what population and what variable.
用期望计数检验大计数条件并写出它们,例如“期望计数为 $80, 60, 40, 20$,都不小于 $5$”。检查观测计数并不能检验这个条件。假设要结合情境:说明是什么总体、什么变量。
- Computing $E$ from the sample proportions, which makes $O=E$ every time.
- Writing $\text{df}=n-1$ instead of the number of categories minus one.
- Writing $H_a$ as "all proportions differ" or giving it a direction.
- 用样本比例计算 $E$,这样 $O=E$ 总成立。
- 把自由度写成 $\text{df}=n-1$,而不是类别数减一。
- 把 $H_a$ 写成“所有比例都不同”或给它加方向。
A student claims a die is fair. State $H_0$ and $H_a$ in context.一名学生声称某骰子是公平的。结合情境写出 $H_0$ 与 $H_a$。
$H_0$: the long-run proportion of each face of this die is $\frac16$, $p_1=\dots=p_6=\frac16$. $H_a$: at least one face has a long-run proportion different from $\frac16$.
$H_0$:该骰子每个点数的长期比例都是 $\frac16$,即 $p_1=\dots=p_6=\frac16$。$H_a$:至少有一个点数的长期比例不是 $\frac16$。
A random sample of $90$ spins is taken from a spinner claimed to have $5$ equal sectors. Find the expected count for each sector and the df.随机抽取 $90$ 次旋转,所用转盘声称有 $5$ 个相等的扇形。求每个扇形的期望计数与自由度。
$E=90\cdot\frac15=18$ for every sector, which is at least $5$, and $\text{df}=5-1=4$.
每个扇形 $E=90\cdot\frac15=18$,不小于 $5$;$\text{df}=5-1=4$。
A test has $4$ categories with claimed proportions $0.50$, $0.30$, $0.15$, $0.05$ and a random sample of $n=30$. Is the large-counts condition met?某检验有 $4$ 个类别,给定比例为 $0.50$、$0.30$、$0.15$、$0.05$,随机样本 $n=30$。大计数条件满足吗?
No. The expected counts are $15$, $9$, $4.5$ and $1.5$; the last two are below $5$.
不满足。期望计数为 $15$、$9$、$4.5$、$1.5$;后两个小于 $5$。
Carrying out a goodness-of-fit test进行拟合优度检验
- Carry out a goodness-of-fit test in four steps: state, plan, do, conclude.
- Compute the test statistic, the degrees of freedom and the p-value, by hand and with the X2GOF-Test (chi-square goodness-of-fit test) on a calculator.
- Write a conclusion that compares the p-value with $\alpha$ and is stated in context, using the words "convincing evidence" or "fail to reject" correctly.
- Use each category's contribution to $\chi^2$ to see which category drives the result.
- 按四步完成拟合优度检验:陈述、计划、计算、结论。
- 手算并用计算器的 X2GOF-Test(卡方拟合优度检验)求检验统计量、自由度与 p 值。
- 写出把 p 值与 $\alpha$ 比较、并结合情境的结论,正确使用“有令人信服的证据”或“不能拒绝”。
- 利用各类别对 $\chi^2$ 的贡献,找出是哪个类别造成了结果。
Carry out the test in four steps. State the hypotheses in context and a significance level $\alpha$. Plan by naming the test (chi-square goodness-of-fit test) and checking the random, 10% and large-counts conditions. Do the calculation: the test statistic $\chi^2=\sum\frac{(O-E)^2}{E}$, the degrees of freedom $k-1$, and the p-value from the right tail. Conclude by comparing the p-value with $\alpha$, in context.
按四步完成检验。陈述:结合情境写出假设和显著性水平 $\alpha$。计划:说出检验名称(卡方拟合优度检验)并检验随机、10% 与大计数条件。计算:检验统计量 $\chi^2=\sum\frac{(O-E)^2}{E}$、自由度 $k-1$,以及右尾 p 值。结论:结合情境,把 p 值与 $\alpha$ 比较。
On a TI-84, put the observed counts in L1 and the expected counts in L2, then press STAT, use the right arrow to reach TESTS, and choose the goodness-of-fit test (called X2GOF-Test, shown with the Greek letter chi on the screen) with Observed: L1, Expected: L2 and df $=k-1$. The output gives the test statistic, the p-value, the df and a list of each category's contribution. This menu item is on newer calculator operating systems; if yours lacks it, compute (L1-L2)^2/L2 into L3, take sum(L3) for $\chi^2$, and use the chi-square cdf from Topic 11.1 for the p-value.
在 TI-84 上,把观测计数放入 L1、期望计数放入 L2,然后按 STAT,用右箭头移到 TESTS,选择拟合优度检验(名为 X2GOF-Test,屏幕上显示希腊字母 chi),设置 Observed: L1,Expected: L2,df $=k-1$。输出包括检验统计量、p 值、自由度以及每个类别的贡献列表。该菜单项在较新的计算器系统中才有;如果你的计算器没有,可把 (L1-L2)^2/L2 存入 L3,用 sum(L3) 得到 $\chi^2$,再用主题 11.1 的卡方累积分布函数求 p 值。
If the p-value is less than $\alpha$, reject $H_0$: there is convincing evidence that the population distribution differs from the claimed distribution in at least one category. If the p-value is at least $\alpha$, fail to reject $H_0$: the data do not provide convincing evidence of a difference. That is not evidence that the claim is true; it only says this sample is consistent with it. Always finish with the context (population and variable).
若 p 值小于 $\alpha$,拒绝 $H_0$:有令人信服的证据表明总体分布至少在一个类别上与给定分布不同。若 p 值不小于 $\alpha$,不能拒绝 $H_0$:数据没有提供令人信服的差异证据。这并不证明该说法是真的,只说明这个样本与它相容。结论最后一定要回到情境(总体与变量)。
Which categories drive the result哪些类别造成了结果
The statistic is a sum of one contribution $\frac{(O-E)^2}{E}$ per category. The category with the largest contribution is where the data disagree most with the claim. The test statistic does not carry a direction, so to say how a category differs, compare its observed and expected counts directly.
统计量是每个类别一项贡献 $\frac{(O-E)^2}{E}$ 的总和。贡献最大的类别就是数据与说法分歧最大之处。统计量本身不带方向,要说明某类别如何不同,需直接比较它的观测计数与期望计数。
Worked Example 8.5: fail to reject the claimed ratio例题 8.5:不能拒绝给定的比例
A plant-breeding model predicts offspring phenotypes in the ratio $9:3:3:1$, so the claimed proportions are $\frac9{16}$, $\frac3{16}$, $\frac3{16}$, $\frac1{16}$. A random sample of $320$ offspring from a very large cross gives $187$, $55$, $62$ and $16$. Test the claim at $\alpha=0.05$. (Illustrative data.)
- State. $H_0$: the offspring phenotypes in this cross follow the $9:3:3:1$ model. $H_a$: at least one phenotype proportion differs from the model.
- Plan. Chi-square goodness-of-fit test. Random: random sample. 10%: $320$ is under $10\%$ of a very large cross. Expected counts are $320\cdot\frac9{16}=180$, $60$, $60$ and $20$, all at least $5$.
- Do. Contributions: $\frac{(187-180)^2}{180}=0.272$, $\frac{(55-60)^2}{60}=0.417$, $\frac{(62-60)^2}{60}=0.067$, $\frac{(16-20)^2}{20}=0.800$. So $\chi^2=1.556$, $\text{df}=3$, and the p-value is
χ²cdf($1.556$, 1E99, $3$) $=0.670$. - Conclude. Because the p-value $0.670$ is greater than $\alpha=0.05$, we fail to reject $H_0$. There is not convincing evidence that the offspring phenotypes in this cross differ from the $9:3:3:1$ ratio. The largest contribution, $0.800$, comes from the rarest phenotype, but it is small in absolute terms. We have not proved the model is right.
某植物育种模型预测子代表现型之比为 $9:3:3:1$,即给定比例为 $\frac9{16}$、$\frac3{16}$、$\frac3{16}$、$\frac1{16}$。从一个很大的杂交群体中随机抽取 $320$ 株子代,各表现型数量为 $187$、$55$、$62$、$16$。在 $\alpha=0.05$ 下检验该说法。(虚构数据。)
- 陈述。$H_0$:该杂交子代的表现型符合 $9:3:3:1$ 模型。$H_a$:至少有一种表现型的比例与模型不同。
- 计划。卡方拟合优度检验。随机:随机样本。10%:$320$ 不到该很大杂交群体的 $10\%$。期望计数为 $320\cdot\frac9{16}=180$、$60$、$60$、$20$,都不小于 $5$。
- 计算。各项贡献:$\frac{(187-180)^2}{180}=0.272$,$\frac{(55-60)^2}{60}=0.417$,$\frac{(62-60)^2}{60}=0.067$,$\frac{(16-20)^2}{20}=0.800$。因此 $\chi^2=1.556$,$\text{df}=3$,p 值为
χ²cdf($1.556$, 1E99, $3$) $=0.670$。 - 结论。因为 p 值 $0.670$ 大于 $\alpha=0.05$,所以不能拒绝 $H_0$。没有令人信服的证据表明该杂交子代的表现型与 $9:3:3:1$ 的比例不同。最大的贡献 $0.800$ 来自最稀少的表现型,但绝对值很小。我们并没有证明该模型正确。
Worked Example 8.6: reject, and find which face drives it例题 8.6:拒绝,并找出是哪个点数造成的
A game designer claims a six-sided die is fair. In $150$ randomly chosen rolls, faces $1$ to $6$ come up $19$, $24$, $22$, $23$, $21$ and $41$ times. Test at $\alpha=0.05$. (Illustrative data.)
- State. $H_0$: the die is fair, so each face has long-run proportion $\frac16$. $H_a$: at least one face has a long-run proportion different from $\frac16$.
- Plan. Chi-square goodness-of-fit test; the rolls are random, and each expected count is $150\cdot\frac16=25$, at least $5$. The 10% condition is not needed because a die has no finite population to sample without replacement.
- Do. Contributions: $\frac{(19-25)^2}{25}=1.44$, $0.04$, $0.36$, $0.16$, $0.64$ and $\frac{(41-25)^2}{25}=10.24$. Then $\chi^2=12.88$, $\text{df}=5$, p-value $=$
χ²cdf($12.88$, 1E99, $5$) $=0.0245$ (Figure 8.2). - Conclude. Because $0.0245<0.05$, we reject $H_0$. There is convincing evidence that the long-run proportions of the faces of this die are not all $\frac16$.
- Which face? Face $6$ contributes $10.24$ of the $12.88$, about $79.5\%$ of the statistic (Figure 8.3). Its observed count $41$ is well above the expected $25$. The test itself only says the die is not fair; the direction comes from comparing the counts.
一位游戏设计师声称某六面骰子是公平的。随机抽取的 $150$ 次投掷中,点数 $1$ 到 $6$ 分别出现 $19$、$24$、$22$、$23$、$21$、$41$ 次。在 $\alpha=0.05$ 下检验。(虚构数据。)
- 陈述。$H_0$:骰子公平,每个点数的长期比例为 $\frac16$。$H_a$:至少有一个点数的长期比例不是 $\frac16$。
- 计划。卡方拟合优度检验;各次投掷是随机的,每个期望计数为 $150\cdot\frac16=25$,不小于 $5$。这里不需要 10% 条件,因为骰子没有可以不放回抽样的有限总体。
- 计算。各项贡献:$\frac{(19-25)^2}{25}=1.44$,$0.04$,$0.36$,$0.16$,$0.64$,以及 $\frac{(41-25)^2}{25}=10.24$。于是 $\chi^2=12.88$,$\text{df}=5$,p 值 $=$
χ²cdf($12.88$, 1E99, $5$) $=0.0245$(图 8.2)。 - 结论。因为 $0.0245<0.05$,拒绝 $H_0$。有令人信服的证据表明,这颗骰子各点数的长期比例并非都是 $\frac16$。
- 是哪个点数?点数 $6$ 贡献了 $10.24$,约占 $12.88$ 的 $79.5\%$(图 8.3)。其观测计数 $41$ 远高于期望的 $25$。检验本身只说明骰子不公平;方向要靠比较计数得出。
Prompt. A manager claims visits to a website are spread equally over the five weekdays. A random sample of $200$ visits from the server log has $52$, $38$, $36$, $34$ and $40$ visits on Monday to Friday. Is there convincing evidence that visits are not spread equally? Use $\alpha=0.05$. (Illustrative data.)
| Part | What a complete answer states |
|---|---|
| Hypotheses | $H_0$: visits to this website are equally likely on each of the five weekdays ($p=0.20$ each). $H_a$: at least one weekday has a different proportion of visits. |
| Conditions | Random sample of visits; $200$ is less than $10\%$ of all visits; expected count $200(0.20)=40$ for each weekday, all at least $5$. |
| Statistic, df, p-value | $\chi^2=\frac{(52-40)^2}{40}+\frac{(38-40)^2}{40}+\frac{(36-40)^2}{40}+\frac{(34-40)^2}{40}+\frac{(40-40)^2}{40}=3.6+0.1+0.4+0.9+0=5.0$; $\text{df}=5-1=4$; p-value $=0.287$. |
| Conclusion | Because $0.287>0.05$, we fail to reject $H_0$. There is not convincing evidence that visits to this website are spread unequally over the weekdays. |
题目。某经理声称一个网站的访问量在五个工作日中均匀分布。从服务器日志中随机抽取 $200$ 次访问,周一至周五分别为 $52$、$38$、$36$、$34$、$40$ 次。是否有令人信服的证据表明访问量分布不均匀?取 $\alpha=0.05$。(虚构数据。)
| 部分 | 完整答案要点 |
|---|---|
| 假设 | $H_0$:该网站在五个工作日的访问概率相等(各为 $p=0.20$)。$H_a$:至少有一个工作日的访问比例不同。 |
| 条件 | 访问记录为随机样本;$200$ 不到全部访问量的 $10\%$;每个工作日期望计数 $200(0.20)=40$,都不小于 $5$。 |
| 统计量、自由度、p 值 | $\chi^2=\frac{(52-40)^2}{40}+\frac{(38-40)^2}{40}+\frac{(36-40)^2}{40}+\frac{(34-40)^2}{40}+\frac{(40-40)^2}{40}=3.6+0.1+0.4+0.9+0=5.0$;$\text{df}=5-1=4$;p 值 $=0.287$。 |
| 结论 | 因为 $0.287>0.05$,不能拒绝 $H_0$。没有令人信服的证据表明该网站的访问量在工作日之间分布不均匀。 |
Statistical significance depends on sample size统计显著性取决于样本量
A chi-square test answers 'is there convincing evidence of a difference', not 'is the difference large'. Multiplying every count by $c$ multiplies $\chi^2$ by $c$ (Topic 11.1), so a pattern that is unremarkable in a small sample can be overwhelming in a large one. In the cafeteria data, the counts $18$, $22$, $30$, $30$ out of $100$ give $\chi^2=4.32$ and a p-value of $0.2289$. The same percentages in a sample of $400$ (counts $72$, $88$, $120$, $120$) give $\chi^2=17.28$ and a p-value of $0.0006$. The percentages did not change; only the amount of evidence did. When you write a conclusion, also say how big the difference is, for example which entrée is over or under chosen and by roughly how many students per hundred, so the reader can judge whether it matters.
卡方检验回答的是“有没有令人信服的差异证据”,而不是“差异有多大”。每个计数都乘以 $c$,$\chi^2$ 就乘以 $c$(见主题 11.1),所以小样本里平平无奇的模式在大样本里可能非常显著。食堂数据中,$100$ 人里的计数 $18$、$22$、$30$、$30$ 得到 $\chi^2=4.32$,p 值为 $0.2289$。同样的百分比放在 $400$ 人的样本中(计数 $72$、$88$、$120$、$120$)得到 $\chi^2=17.28$,p 值为 $0.0006$。百分比没变,变的只是证据的多少。写结论时还要说明差异有多大,例如哪种主菜被选得偏多或偏少、大约每一百名学生差几人,让读者自己判断它是否重要。
Using the test in reverse反向使用检验
A reverse problem fixes the claim and asks what data would give a particular conclusion. Write $\chi^2$ as a formula in the unknown count, set it equal to the critical value for the degrees of freedom, and solve; then test the neighbouring whole numbers, because counts are integers. This is a good way to see how the statistic grows: it grows with the square of the gap between an observed count and its expected count.
反向问题固定给定的说法,问什么样的数据会得到某个结论。把 $\chi^2$ 写成未知计数的式子,令它等于该自由度下的临界值并求解;然后检验相邻的整数,因为计数是整数。这能帮你看清统计量如何增长:它随观测计数与期望计数之差的平方增长。
Worked Example: a reverse problem: how far must a count move?例题:反向问题:计数要偏离多远?
A random sample of $60$ people is sorted into three categories and the claim is that the three are equally likely. The second category has observed count $20$. Let the first category have count $a$, so the third has $40-a$. What is the smallest value of $a$ above $20$ that gives a p-value below $0.05$? (Illustrative.)
- Each expected count is $\frac{60}{3}=20$, and $\text{df}=3-1=2$. The critical value for $\alpha=0.05$ is $5.991$.
- The second category contributes $0$. The other two contribute $\frac{(a-20)^2}{20}$ and $\frac{(40-a-20)^2}{20}=\frac{(20-a)^2}{20}$, so $\chi^2=\frac{(a-20)^2}{10}$.
- Require $\frac{(a-20)^2}{10}>5.991$, which gives $(a-20)^2>59.91$ and $a-20>7.74$.
- Check the integers: $a=27$ gives $\chi^2=4.90$ and a p-value of $0.0863$; $a=28$ gives $\chi^2=6.40$ and a p-value of $0.0408$. So the smallest value is $a=28$, with counts $28$, $20$ and $12$.
- A complete answer states: with counts $28$, $20$, $12$ we reject $H_0$ at $\alpha=0.05$, and there is convincing evidence that the three categories are not equally likely in the population. One fewer person in the first category ($27$) would not be enough.
随机抽取 $60$ 人分成三类,给定的说法是三类可能性相等。第二类的观测计数是 $20$。设第一类计数为 $a$,则第三类为 $40-a$。使 p 值低于 $0.05$ 的、大于 $20$ 的最小 $a$ 是多少?(虚构示例。)
- 每个期望计数为 $\frac{60}{3}=20$,$\text{df}=3-1=2$。$\alpha=0.05$ 的临界值为 $5.991$。
- 第二类贡献 $0$。另外两类贡献 $\frac{(a-20)^2}{20}$ 和 $\frac{(40-a-20)^2}{20}=\frac{(20-a)^2}{20}$,所以 $\chi^2=\frac{(a-20)^2}{10}$。
- 要求 $\frac{(a-20)^2}{10}>5.991$,得到 $(a-20)^2>59.91$,即 $a-20>7.74$。
- 检验整数:$a=27$ 时 $\chi^2=4.90$,p 值 $0.0863$;$a=28$ 时 $\chi^2=6.40$,p 值 $0.0408$。所以最小值是 $a=28$,计数为 $28$、$20$、$12$。
- 完整答案要点:计数为 $28$、$20$、$12$ 时,在 $\alpha=0.05$ 下拒绝 $H_0$,有令人信服的证据表明总体中三个类别的可能性并不相等。第一类少一个人($27$)则不够。
In a die test with expected count $25$ per face, face $2$ has $O=10$ and face $5$ has $O=40$. Each contributes $\frac{(\pm 15)^2}{25}=9.0$. A student writes 'both faces contribute a lot, so both come up too often'. A contribution is a square, so it is never negative and it hides the direction: face $2$ is far below expectation and face $5$ is far above. The fix: use the contribution to find which categories disagree most with $H_0$, then compare $O$ with $E$ for each of those categories to say whether it is higher or lower than claimed.
在期望计数为每个点数 $25$ 的骰子检验中,点数 $2$ 的 $O=10$,点数 $5$ 的 $O=40$,两者的贡献都是 $\frac{(\pm 15)^2}{25}=9.0$。某学生写道“两个点数的贡献都很大,所以都出现得太频繁”。贡献是平方,永远不为负,它隐藏了方向:点数 $2$ 远低于期望,点数 $5$ 远高于期望。正确做法:先用贡献找出与 $H_0$ 分歧最大的类别,再对这些类别比较 $O$ 与 $E$,说明它比给定的说法偏高还是偏低。
Finish with a sentence in context that compares the p-value with $\alpha$ and names the population and variable. Say "fail to reject $H_0$" and "not convincing evidence", never "accept $H_0$". If asked which category contributes most, give the number and compare $O$ with $E$ for that category.
最后写一句结合情境的话:把 p 值与 $\alpha$ 比较,并写明总体与变量。要说“不能拒绝 $H_0$”和“没有令人信服的证据”,不要说“接受 $H_0$”。若问哪个类别贡献最大,给出数值并比较该类别的 $O$ 与 $E$。
- Saying "accept $H_0$", or reading a large p-value as proof that the claim is true.
- Interpreting the p-value as the probability that $H_0$ is true. It is the probability of a statistic at least this large when $H_0$ is true.
- Concluding that a face is "biased high" from the test alone; the test does not give direction.
- 说“接受 $H_0$”,或把大的 p 值当成说法正确的证明。
- 把 p 值解释为 $H_0$ 为真的概率。它是 $H_0$ 为真时统计量至少这么大的概率。
- 仅凭检验就断定某点数“偏高”;检验本身不给出方向。
A goodness-of-fit test with $3$ categories gives $\chi^2=6.2$. Find the p-value and state the conclusion at $\alpha=0.05$.一个有 $3$ 个类别的拟合优度检验得到 $\chi^2=6.2$。求 p 值,并在 $\alpha=0.05$ 下写出结论。
$\text{df}=2$, p-value $=$ χ²cdf($6.2$, 1E99, $2$) $=0.045$. Because $0.045<0.05$, reject $H_0$: there is convincing evidence that the population distribution differs from the claimed one in at least one category.
$\text{df}=2$,p 值 $=$ χ²cdf($6.2$, 1E99, $2$) $=0.045$。因为 $0.045<0.05$,拒绝 $H_0$:有令人信服的证据表明总体分布至少在一个类别上与给定分布不同。
A random sample of $100$ has observed counts $18$, $30$, $52$ against claimed proportions $0.25$, $0.25$, $0.50$. Which category has the largest contribution, and what is $\chi^2$?对 $100$ 个个体的随机样本,观测计数为 $18$、$30$、$52$,给定比例为 $0.25$、$0.25$、$0.50$。哪个类别贡献最大?$\chi^2$ 是多少?
Expected counts are $25$, $25$, $50$. Contributions: $\frac{(18-25)^2}{25}=1.96$, $\frac{(30-25)^2}{25}=1.00$, $\frac{(52-50)^2}{50}=0.08$. The first category is largest, and $\chi^2=3.04$.
期望计数为 $25$、$25$、$50$。各项贡献:$\frac{(18-25)^2}{25}=1.96$,$\frac{(30-25)^2}{25}=1.00$,$\frac{(52-50)^2}{50}=0.08$。第一个类别最大,$\chi^2=3.04$。
Interpret the p-value $0.0245$ from Worked Example 8.6 in context.结合情境解释例题 8.6 中的 p 值 $0.0245$。
If this die were fair, the probability of getting a chi-square statistic at least as large as $12.88$ from $150$ random rolls is $0.0245$.
如果这颗骰子是公平的,那么得到至少为 $12.88$ 的卡方统计量(来自 $150$ 次随机投掷)的概率是 $0.0245$。
Expected counts in a two-way table双向表中的期望计数
- Read a two-way table: row totals, column totals and the table (grand) total.
- Compute expected counts with $E=\frac{(\text{row total})(\text{column total})}{\text{table total}}$.
- Explain what an expected count represents when there is no association between the variables.
- Check that the expected counts are all at least $5$ and that they reproduce the observed margins.
- 读懂双向表:行合计、列合计与表总计。
- 用 $E=\frac{(\text{row total})(\text{column total})}{\text{table total}}$ 计算期望计数。
- 说明变量之间无关联时,期望计数代表什么。
- 检验所有期望计数不小于 $5$,并检查它们与观测表的边际合计一致。
A two-way table cross-classifies counts by two categorical variables (or by group and outcome). Each row has a row total, each column has a column total, and the table total (grand total) $n$ is the sum of all cells. These totals are the marginal counts, and they are all you need to build the expected counts.
双向表按两个分类变量(或按组别与结果)对计数做交叉分类。每行有行合计,每列有列合计,表总计(总合计)$n$ 是所有单元格之和。这些合计就是边际计数,构造期望计数只需要它们。
Here is the idea. Suppose the null hypothesis holds: every row is spread across the columns in the same way as the whole sample. The overall proportion of the sample in a column is $\frac{\text{column total}}{\text{table total}}$, so a row with $\text{row total}$ individuals should have about $\text{row total}\times\frac{\text{column total}}{\text{table total}}$ of them in that column.
思路如下。假设原假设成立:每一行在各列上的分布都与整个样本相同。样本中属于某一列的总体比例是 $\frac{\text{column total}}{\text{table total}}$,所以有 $\text{row total}$ 个个体的一行,在该列中应有约 $\text{row total}\times\frac{\text{column total}}{\text{table total}}$ 个。
Expected count in a cell $=\dfrac{(\text{row total})(\text{column total})}{\text{table total}}$. Keep decimals (do not round to whole numbers), and remember each row and each column of expected counts adds to the same total as in the observed table.
单元格的期望计数 $=\dfrac{(\text{row total})(\text{column total})}{\text{table total}}$。保留小数(不要取整),并记住期望计数表的每行每列之和都与观测表相同。
Worked Example 8.7: build the expected table from the margins例题 8.7:由边际合计构造期望表
A random sample of $60$ sophomores and a separate random sample of $90$ seniors at one school are asked how they usually get to school. (Illustrative data.)
| Bus | Car | Walk | Row total | |
|---|---|---|---|---|
| Sophomores | 30 | 18 | 12 | 60 |
| Seniors | 25 | 45 | 20 | 90 |
| Column total | 55 | 63 | 32 | 150 |
- Sophomores, Bus: $E=\frac{(60)(55)}{150}=22$. Sophomores, Car: $E=\frac{(60)(63)}{150}=25.2$. Sophomores, Walk: $E=\frac{(60)(32)}{150}=12.8$.
- Seniors, Bus: $E=\frac{(90)(55)}{150}=33$. Seniors, Car: $E=\frac{(90)(63)}{150}=37.8$. Seniors, Walk: $E=\frac{(90)(32)}{150}=19.2$.
- Check the margins: $22+25.2+12.8=60$ and $33+37.8+19.2=90$; $22+33=55$, $25.2+37.8=63$, $12.8+19.2=32$. All six expected counts are at least $5$, the smallest being $12.8$.
| Expected | Bus | Car | Walk | Row total |
|---|---|---|---|---|
| Sophomores | 22 | 25.2 | 12.8 | 60 |
| Seniors | 33 | 37.8 | 19.2 | 90 |
| Column total | 55 | 63 | 32 | 150 |
某校分别随机抽取 $60$ 名高二学生和 $90$ 名高三学生,询问他们通常如何上学。(虚构数据。)
| 公交 | 汽车 | 步行 | 行合计 | |
|---|---|---|---|---|
| 高二 | 30 | 18 | 12 | 60 |
| 高三 | 25 | 45 | 20 | 90 |
| 列合计 | 55 | 63 | 32 | 150 |
- 高二、公交:$E=\frac{(60)(55)}{150}=22$。高二、汽车:$E=\frac{(60)(63)}{150}=25.2$。高二、步行:$E=\frac{(60)(32)}{150}=12.8$。
- 高三、公交:$E=\frac{(90)(55)}{150}=33$。高三、汽车:$E=\frac{(90)(63)}{150}=37.8$。高三、步行:$E=\frac{(90)(32)}{150}=19.2$。
- 核对边际合计:$22+25.2+12.8=60$,$33+37.8+19.2=90$;$22+33=55$,$25.2+37.8=63$,$12.8+19.2=32$。六个期望计数都不小于 $5$,最小为 $12.8$。
| 期望 | 公交 | 汽车 | 步行 | 行合计 |
|---|---|---|---|---|
| 高二 | 22 | 25.2 | 12.8 | 60 |
| 高三 | 33 | 37.8 | 19.2 | 90 |
| 列合计 | 55 | 63 | 32 | 150 |
Worked Example 8.8: a table that fails the large-counts condition例题 8.8:不满足大计数条件的表
In a small random study, $22$ patients are classified by treatment and outcome: Treatment A has $4$ improved and $6$ not improved; Treatment B has $9$ improved and $3$ not improved. (Illustrative data.)
- Row totals are $10$ and $12$; column totals are $13$ (improved) and $9$ (not improved); the table total is $22$.
- Expected counts: $\frac{(10)(13)}{22}=5.91$, $\frac{(10)(9)}{22}=4.09$, $\frac{(12)(13)}{22}=7.09$, $\frac{(12)(9)}{22}=4.91$.
- Two expected counts, $4.09$ and $4.91$, are below $5$, so the large-counts condition fails and a chi-square test should not be used. Note that all the observed counts could be above $5$ and the condition would still fail: it is about expected counts.
在一项小型随机研究中,$22$ 名患者按治疗方式与结果分类:治疗 A 有 $4$ 人好转、$6$ 人未好转;治疗 B 有 $9$ 人好转、$3$ 人未好转。(虚构数据。)
- 行合计为 $10$ 和 $12$;列合计为 $13$(好转)和 $9$(未好转);表总计为 $22$。
- 期望计数:$\frac{(10)(13)}{22}=5.91$,$\frac{(10)(9)}{22}=4.09$,$\frac{(12)(13)}{22}=7.09$,$\frac{(12)(9)}{22}=4.91$。
- 有两个期望计数 $4.09$ 和 $4.91$ 小于 $5$,大计数条件不满足,不应使用卡方检验。注意:即使所有观测计数都大于 $5$,这个条件仍可能不满足:它针对的是期望计数。
How many expected counts must you compute?需要计算几个期望计数?
In a table with $r$ rows and $c$ columns of data, once the first $r-1$ rows and $c-1$ columns of expected counts are found, every other cell is fixed, because each row and column of expected counts must add to the observed total. That is why $\text{df}=(r-1)(c-1)$: it is the number of cells you are free to fill. A $2\times 2$ table needs only one cell by the formula ($\text{df}=1$) and the other three follow by subtraction. A $2\times 3$ table needs two ($\text{df}=2$). Computing one extra cell by the formula is a quick check on your subtraction.
在数据为 $r$ 行 $c$ 列的表中,一旦求出前 $r-1$ 行和前 $c-1$ 列的期望计数,其余单元格就都确定了,因为期望计数的每行每列之和必须等于观测的合计。这就是 $\text{df}=(r-1)(c-1)$ 的由来:它是你可以自由填写的单元格数。$2\times 2$ 表用公式只需算一个单元格($\text{df}=1$),其余三个靠减法得到;$2\times 3$ 表需要算两个($\text{df}=2$)。多用公式算一个单元格,是检查减法的快速办法。
Checking an expected table before you use it使用前检查期望表
Run three checks before computing $\chi^2$. First, every row of expected counts adds to its observed row total and every column to its observed column total. Second, the smallest expected count is at least $5$, and you say what it is. Third, rows that have the same total have identical expected counts, because under $H_0$ each row is spread across the columns in the same way. Keep at least one decimal place: expected counts are averages, so they are rarely whole numbers, and rounding them changes the statistic.
算 $\chi^2$ 之前做三项检查。第一,期望计数的每一行之和等于观测的行合计,每一列之和等于观测的列合计。第二,最小的期望计数不小于 $5$,并写出它是多少。第三,行合计相同的行,期望计数也相同,因为在 $H_0$ 下每一行在各列上的分布都一样。至少保留一位小数:期望计数是平均值,很少是整数,把它们取整会改变统计量。
Worked Example: compute two cells and fill in the rest by subtraction例题:只算两个单元格,其余用减法
Random samples of $100$ students are taken from each of two schools, and each student chooses a favorite lunch option. Group A gives $30$, $45$ and $25$ students for options 1, 2 and 3, and Group B gives $50$, $35$ and $15$. Find the expected counts, check the conditions on them and compute $\chi^2$. (Illustrative.)
- The row totals are $100$ and $100$, the column totals are $80$, $80$ and $40$, and the table total is $200$.
- With $\text{df}=(2-1)(3-1)=2$, two cells use the formula: $E_{A1}=\frac{(100)(80)}{200}=40$ and $E_{A2}=\frac{(100)(80)}{200}=40$.
- Fill in by subtraction. $E_{A3}=100-40-40=20$. Group B: $80-40=40$, $80-40=40$ and $40-20=20$. Check with the formula: $\frac{(100)(40)}{200}=20$.
- Large counts: the smallest expected count is $20$, which is at least $5$. The two rows are identical because the two row totals are equal.
- Contributions for each row: $\frac{(30-40)^2}{40}=2.5$, $\frac{(45-40)^2}{40}=0.625$ and $\frac{(25-20)^2}{20}=1.25$ for Group A, and $2.5$, $0.625$ and $1.25$ for Group B, because each Group B difference has the same size.
- $\chi^2=2(2.5+0.625+1.25)=8.75$ and $\text{df}=2$, so the p-value is
χ²cdf($8.75$, 1E99, $2$) $=0.0126$.
从两所学校各随机抽取 $100$ 名学生,每人选择最喜欢的午餐选项。A 组选择选项 1、2、3 的人数为 $30$、$45$、$25$,B 组为 $50$、$35$、$15$。求期望计数,检验条件并计算 $\chi^2$。(虚构示例。)
- 行合计为 $100$ 和 $100$,列合计为 $80$、$80$、$40$,表总计为 $200$。
- $\text{df}=(2-1)(3-1)=2$,所以有两个单元格用公式:$E_{A1}=\frac{(100)(80)}{200}=40$,$E_{A2}=\frac{(100)(80)}{200}=40$。
- 其余用减法。$E_{A3}=100-40-40=20$。B 组:$80-40=40$,$80-40=40$,$40-20=20$。用公式核对:$\frac{(100)(40)}{200}=20$。
- 大计数:最小的期望计数是 $20$,不小于 $5$。两行的行合计相等,所以两行完全一样。
- 各行的贡献:A 组为 $\frac{(30-40)^2}{40}=2.5$、$\frac{(45-40)^2}{40}=0.625$、$\frac{(25-20)^2}{20}=1.25$,B 组为 $2.5$、$0.625$、$1.25$,因为 B 组每个差的大小都相同。
- $\chi^2=2(2.5+0.625+1.25)=8.75$,$\text{df}=2$,所以 p 值为
χ²cdf($8.75$, 1E99, $2$) $=0.0126$。
Take the table with rows $20$, $10$ and $8$, $12$. The expected counts are $16.8$, $13.2$, $11.2$ and $8.8$, which give $\chi^2=3.46$ and a p-value of $0.0627$. A student rounds them to $17$, $13$, $11$ and $9$ and gets $\chi^2=3.04$ and a p-value of $0.0812$. At $\alpha=0.07$ the correct work rejects $H_0$ and the rounded work does not. The fix: carry the decimals through the calculation and round only the final statistic and p-value.
取一张两行数据为 $20$、$10$ 和 $8$、$12$ 的表。期望计数为 $16.8$、$13.2$、$11.2$、$8.8$,得到 $\chi^2=3.46$,p 值为 $0.0627$。某学生把它们取整为 $17$、$13$、$11$、$9$,得到 $\chi^2=3.04$,p 值为 $0.0812$。在 $\alpha=0.07$ 下,正确的计算拒绝 $H_0$,取整后的计算却不拒绝。正确做法:计算过程中保留小数,只对最后的统计量和 p 值取整。
Show at least one expected count with its row total, column total and table total, such as $\frac{(60)(55)}{150}$, then say the smallest expected count and that it is at least $5$. A calculator matrix can produce the expected counts for you, but a written answer still needs to state them or the check.
至少展示一个期望计数及其行合计、列合计和表总计,例如 $\frac{(60)(55)}{150}$,然后说明最小的期望计数并指出它不小于 $5$。计算器矩阵可以替你算出期望计数,但书面答案仍需写出它们或这项检验。
- Using row total times column total without dividing by the table total.
- Checking the large-counts condition on the observed counts.
- Rounding expected counts to whole numbers before using them in $\frac{(O-E)^2}{E}$.
- 只用行合计乘列合计而不除以表总计。
- 对观测计数而不是期望计数检验大计数条件。
- 在代入 $\frac{(O-E)^2}{E}$ 之前把期望计数取整。
A cell has row total $40$, column total $70$ and the table total is $200$. Find its expected count.某单元格的行合计为 $40$,列合计为 $70$,表总计为 $200$。求它的期望计数。
$E=\frac{(40)(70)}{200}=14$.
$E=\frac{(40)(70)}{200}=14$。
A student's expected counts in one row add to $58$, but that row's observed total is $60$. What does this tell you?一名学生算出的某一行期望计数之和为 $58$,而该行观测合计为 $60$。这说明什么?
There is an arithmetic error. Expected counts must reproduce every row total and column total of the observed table.
计算有误。期望计数必须与观测表的每个行合计和列合计一致。
A $2\times 2$ table has row totals $30$ and $20$, column totals $35$ and $15$, and table total $50$. Is the large-counts condition met?一个 $2\times 2$ 表的行合计为 $30$ 和 $20$,列合计为 $35$ 和 $15$,表总计为 $50$。大计数条件满足吗?
The expected counts are $\frac{(30)(35)}{50}=21$, $\frac{(30)(15)}{50}=9$, $\frac{(20)(35)}{50}=14$, $\frac{(20)(15)}{50}=6$. The smallest is $6$, so yes, all are at least $5$.
期望计数为 $\frac{(30)(35)}{50}=21$,$\frac{(30)(15)}{50}=9$,$\frac{(20)(35)}{50}=14$,$\frac{(20)(15)}{50}=6$。最小为 $6$,所以满足,全部不小于 $5$。
Homogeneity and independence: design and hypotheses同质性与独立性:设计与假设
- Tell a test of homogeneity from a test of independence by how the data were collected.
- Write the null and alternative hypotheses for each test in context.
- State the degrees of freedom $(r-1)(c-1)$ for a two-way table.
- Check the conditions: random samples or random assignment, 10%, and all expected counts at least $5$.
- 根据数据的收集方式区分同质性检验与独立性检验。
- 结合情境写出每种检验的原假设与备择假设。
- 写出双向表的自由度 $(r-1)(c-1)$。
- 检验条件:随机样本或随机分配、10%、所有期望计数不小于 $5$。
Two different questions lead to the same table, the same expected counts, the same statistic and the same degrees of freedom. What differs is how the data were collected, and therefore what the null hypothesis says. A test of homogeneity compares the distribution of one categorical variable across several groups. A test of independence asks whether two categorical variables are associated within one population.
两类不同的问题会得到同样的表、同样的期望计数、同样的统计量和同样的自由度。不同之处在于数据是怎样收集的,因此原假设的表述也不同。同质性检验比较一个分类变量在多个组中的分布。独立性检验问同一总体中两个分类变量是否有关联。
| Test of homogeneity | Test of independence | |
|---|---|---|
| Design | Separate random samples from several populations, or random assignment of units to several treatments | One random sample from one population |
| Variables measured | One categorical variable, in each group | Two categorical variables on every individual |
| Null hypothesis | The distribution of the variable is the same in all the populations (or treatments) | The two variables are independent in the population (no association) |
| Alternative hypothesis | The distribution differs in at least one population (treatment) | The two variables are associated |
| Sample sizes | Group sizes are set by the researcher | Row totals are a result of the sampling |
| 同质性检验 | 独立性检验 | |
|---|---|---|
| 设计 | 从多个总体分别随机抽样,或把个体随机分配到多种处理 | 从一个总体抽取一个随机样本 |
| 测量的变量 | 每组中测量一个分类变量 | 每个个体测量两个分类变量 |
| 原假设 | 该变量在所有总体(或处理)中的分布相同 | 两变量在总体中相互独立(无关联) |
| 备择假设 | 至少有一个总体(处理)的分布不同 | 两变量有关联 |
| 样本量 | 各组样本量由研究者设定 | 行合计是抽样的结果 |
For a table with $r$ rows and $c$ columns (not counting the totals), $\text{df}=(r-1)(c-1)$. The conditions are: the data come from random samples (or from a randomized experiment); the 10% condition holds for each sample drawn without replacement; and every expected count is at least $5$.
对有 $r$ 行 $c$ 列的表(不含合计),$\text{df}=(r-1)(c-1)$。条件包括:数据来自随机样本(或随机化实验);每个不放回抽取的样本满足 10% 条件;每个期望计数都不小于 $5$。
Worked Example 8.9: identify the test and write the hypotheses例题 8.9:识别检验类型并写出假设
(a) A bank draws a separate random sample of $100$ customers from each of its $3$ branches and records whether each customer is very satisfied, satisfied, neutral or dissatisfied. (b) A news site takes one random sample of $300$ adults in a city and records each adult's age group ($3$ groups) and preferred news source ($3$ sources). (Illustrative scenarios.)
- (a) Homogeneity: separate samples, one categorical variable. $H_0$: the distribution of satisfaction level is the same at all three branches. $H_a$: the distribution of satisfaction level differs for at least one branch. The table is $3\times 4$, so $\text{df}=(3-1)(4-1)=6$.
- (b) Independence: one sample, two categorical variables. $H_0$: age group and preferred news source are independent for adults in this city. $H_a$: age group and preferred news source are associated for adults in this city. The table is $3\times 3$, so $\text{df}=(3-1)(3-1)=4$.
(a) 一家银行分别随机抽取 $100$ 名客户,他们来自其 $3$ 家分行中的每一家,记录每位客户是非常满意、满意、一般还是不满意。(b) 一个新闻网站对某市成年人抽取一个 $300$ 人的随机样本,记录每人的年龄组($3$ 组)和首选新闻来源($3$ 种)。(虚构情境。)
- (a) 同质性:分别抽样,一个分类变量。$H_0$:三家分行的满意度分布相同。$H_a$:至少有一家分行的满意度分布不同。表为 $3\times 4$,所以 $\text{df}=(3-1)(4-1)=6$。
- (b) 独立性:一个样本,两个分类变量。$H_0$:该市成年人的年龄组与首选新闻来源相互独立。$H_a$:该市成年人的年龄组与首选新闻来源有关联。表为 $3\times 3$,所以 $\text{df}=(3-1)(3-1)=4$。
Worked Example 8.10: check the conditions on a real table例题 8.10:对一张具体的表检验条件
The news-site sample in (b) gives these observed counts: $18$ to $34$: $63$ online, $17$ TV, $10$ print; $35$ to $54$: $60$, $40$, $20$; $55$ and over: $27$, $33$, $30$.
- Row totals are $90$, $120$, $90$; column totals are $150$, $90$, $60$; the table total is $300$.
- Expected counts: row $18$ to $34$: $\frac{(90)(150)}{300}=45$, $\frac{(90)(90)}{300}=27$, $\frac{(90)(60)}{300}=18$. Row $35$ to $54$: $60$, $36$, $24$. Row $55$ and over: $45$, $27$, $18$.
- Random: the adults are a random sample. 10%: $300$ is less than $10\%$ of the adults in a city. Large counts: the smallest expected count is $18$, which is at least $5$.
- All conditions are met, so the chi-square test of independence is appropriate with $\text{df}=4$. The test itself is carried out in Topic 11.6.
(b) 中新闻网站的样本给出如下观测计数:$18$ 至 $34$ 岁:网络 $63$、电视 $17$、纸媒 $10$;$35$ 至 $54$ 岁:$60$、$40$、$20$;$55$ 岁及以上:$27$、$33$、$30$。
- 行合计为 $90$、$120$、$90$;列合计为 $150$、$90$、$60$;表总计为 $300$。
- 期望计数:$18$ 至 $34$ 岁一行:$\frac{(90)(150)}{300}=45$,$\frac{(90)(90)}{300}=27$,$\frac{(90)(60)}{300}=18$。$35$ 至 $54$ 岁一行:$60$、$36$、$24$。$55$ 岁及以上一行:$45$、$27$、$18$。
- 随机:这些成年人是随机样本。10%:$300$ 不到一个城市成年人数的 $10\%$。大计数:最小的期望计数为 $18$,不小于 $5$。
- 所有条件都满足,因此可以做卡方独立性检验,$\text{df}=4$。检验本身在主题 11.6 中完成。
Deciding from the description, one question at a time根据题目描述,一个问题一个问题地判断
Ask two questions about the design. First, did the researcher fix the group sizes in advance, by taking a separate random sample from each group or by randomly assigning units to treatments? That is a test of homogeneity. Second, was one sample taken, with every individual measured on two categorical variables, so that the group sizes are a result of the sampling? That is a test of independence. Wording such as 'compare the distributions' or 'is there an association' is a weaker clue than the design, so use it only to confirm your choice. If it is unclear, find where the totals came from: a total the researcher chose in advance marks a sample size that was fixed.
对研究设计问两个问题。第一,研究者是否事先确定了各组的样本量,即分别从每个组抽取随机样本,或把个体随机分配到各处理?那就是同质性检验。第二,是否只抽取了一个样本,并对每个个体测量两个分类变量,使得各组人数是抽样的结果?那就是独立性检验。“比较分布”或“是否有关联”这样的措辞不如设计可靠,只用来印证你的判断。如果拿不准,就看各个合计从何而来:研究者事先选定的合计说明样本量是固定的。
Same table, two sets of hypotheses同一张表,两套假设
Because the calculation is identical, the table alone cannot tell you which test it is. Write $H_0$ and $H_a$ in the language of the design, and write the conclusion in the same language. For homogeneity: 'the distribution of the variable is the same in every group'. For independence: 'the two variables are independent in the population'. A conclusion about association after a test of homogeneity, or about equal distributions after a test of independence, answers a question the design did not ask.
因为计算过程完全相同,仅凭表格无法判断是哪种检验。用与设计对应的语言写出 $H_0$ 和 $H_a$,结论也用同样的语言。同质性:“该变量的分布在每个组中相同”。独立性:“两个变量在总体中相互独立”。同质性检验之后谈关联,或独立性检验之后谈分布相同,回答的都是设计没有提出的问题。
Worked Example: one table, two designs例题:一张表,两种设计
The table shows how students get to school: bike, bus or car. The counts are $60$, $90$, $50$ in the first row and $40$, $110$, $50$ in the second row. Write the hypotheses and run the test under each of these designs. Design 1: a random sample of $200$ students is taken from each of two schools. Design 2: a random sample of $400$ students is taken from the district, and each student is classified by school and by transport. (Illustrative.)
- Design 1 has separate random samples with the sizes chosen in advance, so it is a test of homogeneity. $H_0$: the distribution of transport is the same at the two schools. $H_a$: the distribution differs.
- Design 2 has one random sample and two categorical variables, so it is a test of independence. $H_0$: school and transport are independent among students in the district. $H_a$: they are associated.
- The calculation is the same for both. Row totals are $200$ and $200$, column totals are $100$, $200$, $100$ and the table total is $400$, so every row of expected counts is $50$, $100$, $50$, all at least $5$.
- Contributions in each row: $\frac{(60-50)^2}{50}=2$, $\frac{(90-100)^2}{100}=1$ and $0$; the second row gives $2$, $1$ and $0$. So $\chi^2=6.0$, $\text{df}=(2-1)(3-1)=2$ and the p-value is
χ²cdf($6.0$, 1E99, $2$) $=0.0498$. - A complete answer states, for Design 1: since $0.0498<0.05$, reject $H_0$; there is convincing evidence that the distribution of transport differs between the two schools. For Design 2: there is convincing evidence of an association between school and transport among students in the district.
- The p-value is only just below $\alpha$, so report it rather than only the decision, and notice that a slightly different sample could have gone the other way.
下表给出学生上学的方式:骑车、公交或私家车。第一行计数为 $60$、$90$、$50$,第二行为 $40$、$110$、$50$。请分别在下面两种设计下写出假设并进行检验。设计 1:从两所学校各随机抽取 $200$ 名学生。设计 2:从某区随机抽取 $400$ 名学生,每人按学校和上学方式分类。(虚构示例。)
- 设计 1 是分别抽取的随机样本,样本量事先确定,所以是同质性检验。$H_0$:两所学校上学方式的分布相同。$H_a$:分布不同。
- 设计 2 是一个随机样本、两个分类变量,所以是独立性检验。$H_0$:该区学生的学校与上学方式相互独立。$H_a$:两者有关联。
- 两种设计的计算相同。行合计为 $200$ 和 $200$,列合计为 $100$、$200$、$100$,表总计为 $400$,所以每一行的期望计数都是 $50$、$100$、$50$,均不小于 $5$。
- 每一行的贡献:$\frac{(60-50)^2}{50}=2$,$\frac{(90-100)^2}{100}=1$,以及 $0$;第二行同样是 $2$、$1$、$0$。所以 $\chi^2=6.0$,$\text{df}=(2-1)(3-1)=2$,p 值为
χ²cdf($6.0$, 1E99, $2$) $=0.0498$。 - 完整答案要点,设计 1:因为 $0.0498<0.05$,拒绝 $H_0$;有令人信服的证据表明两所学校的上学方式分布不同。设计 2:有令人信服的证据表明该区学生的学校与上学方式之间存在关联。
- p 值只比 $\alpha$ 略小,所以要写出 p 值而不只是决定,并注意样本稍有不同,结果就可能相反。
For Design 1 above a student writes '$H_0$: school and transport are independent'. But the researcher chose $200$ students from each school, so the school sizes were set by the design and school is not a variable measured on a random sample of students. The question the design can answer is whether the distribution of transport is the same in each school. The fix: for separate random samples or randomized treatment groups, state $H_0$ as 'the distribution of the variable is the same in all the groups' and name the populations.
对上面的设计 1,某学生写“$H_0$:学校与上学方式相互独立”。但研究者从每所学校各选了 $200$ 名学生,学校的人数是由设计决定的,学校并不是在一个随机样本上测得的变量。该设计能回答的问题是各校上学方式的分布是否相同。正确做法:对分别抽取的随机样本或随机分组的处理组,把 $H_0$ 写成“该变量的分布在所有组中相同”,并指明各个总体。
Say which test it is in the first sentence of your answer and base that choice on the design, not on the shape of the table. Hypotheses must match the design: "the distribution is the same in every group" for homogeneity, "the variables are independent" (or "not associated") for independence, each with the population named.
答案第一句就说明是哪种检验,并依据设计而不是表的形状来选择。假设必须与设计相符:同质性检验写“每组的分布相同”,独立性检验写“两个变量相互独立”(或“无关联”),并写明总体。
- Deciding between the two tests from the table, which looks the same either way.
- Counting the totals row or column when finding $r$ and $c$, which inflates the degrees of freedom.
- Writing a homogeneity null as "the variables are independent" or the reverse.
- 根据表格来判断检验类型,而两者的表格看起来是一样的。
- 求 $r$ 和 $c$ 时把合计行或合计列也算进去,使自由度偏大。
- 把同质性检验的原假设写成“变量独立”,或者反过来。
Ninety volunteers are randomly assigned to one of $3$ diets, and each is later classified as having met a weight goal or not. Which test, and what is the df?90 名志愿者被随机分配到 $3$ 种饮食之一,之后每人被分为达到或未达到体重目标。应做哪种检验?自由度是多少?
Homogeneity (random assignment to several treatments, one categorical outcome). The table is $3\times 2$, so $\text{df}=(3-1)(2-1)=2$.
同质性检验(随机分配到多种处理,一个分类结果)。表为 $3\times 2$,所以 $\text{df}=(3-1)(2-1)=2$。
One random sample of $500$ voters is classified by region ($4$ regions) and preferred candidate ($3$ candidates). Which test, and what is the df?对 $500$ 名选民的一个随机样本,按地区($4$ 个)和支持的候选人($3$ 位)分类。应做哪种检验?自由度是多少?
Independence (one sample, two categorical variables). $\text{df}=(4-1)(3-1)=6$.
独立性检验(一个样本,两个分类变量)。$\text{df}=(4-1)(3-1)=6$。
A table has $4$ rows and $5$ columns of data. What is the df?一张表有 $4$ 行 $5$ 列数据。自由度是多少?
$\text{df}=(4-1)(5-1)=12$.
$\text{df}=(4-1)(5-1)=12$。
Carrying out a chi-square test on a table对双向表进行卡方检验
- Enter a two-way table in a calculator matrix and run the chi-square test of homogeneity or independence.
- Report the test statistic, df and p-value and write a conclusion in context.
- Use each cell's contribution to see where the observed counts differ most from the expected counts.
- Explain why a significant chi-square result shows an association but does not show causation or direction.
- 把双向表输入计算器矩阵,进行卡方同质性或独立性检验。
- 报告检验统计量、自由度与 p 值,并结合情境写出结论。
- 利用各单元格的贡献,看观测计数与期望计数在哪里差别最大。
- 说明为什么显著的卡方结果只表明有关联,而不表明因果或方向。
The four steps are the same as for goodness of fit. State the hypotheses that match the design. Plan with the test name and the conditions, including the expected counts. Do the calculation. Conclude by comparing the p-value with $\alpha$ in context.
步骤与拟合优度检验相同。陈述与设计相符的假设。计划:写出检验名称与条件,包括期望计数。计算。结论:结合情境,把 p 值与 $\alpha$ 比较。
On a TI-84: press 2nd then x-1 for MATRIX, go to EDIT, choose [A], set the dimensions to rows $\times$ columns, and enter the observed counts only (no totals). Then press STAT, use the right arrow to reach TESTS, and choose the chi-square test (written X2-Test; it uses the matrix), with Observed: [A] and Expected: [B], and Calculate. The output gives the test statistic, the p-value and the df, and stores the expected counts in matrix [B], where you can view them under MATRIX to check the large-counts condition. The calculator does not list each cell's contribution; compute $\frac{(O-E)^2}{E}$ for the cells you care about.
在 TI-84 上:按 2nd 再按 x-1 进入 MATRIX,进入 EDIT,选择 [A],把维数设为 行 $\times$ 列,只输入观测计数(不含合计)。然后按 STAT,用右箭头移到 TESTS,选择卡方检验(写作 X2-Test,使用矩阵),设置 Observed: [A]、Expected: [B],再 Calculate。输出包括检验统计量、p 值与自由度,并把期望计数存入矩阵 [B],可在 MATRIX 中查看以检验大计数条件。计算器不会列出各单元格的贡献,需要时自行计算 $\frac{(O-E)^2}{E}$。
Rejecting $H_0$ gives convincing evidence of an association (independence) or of different distributions (homogeneity). The test says nothing about direction or about why. A cause-and-effect conclusion is allowed only when the data come from a randomized experiment, because random assignment, not the chi-square calculation, rules out confounding. After a survey or other observational study, say "associated", never "causes", and state the conclusion in context.
拒绝 $H_0$ 只说明有令人信服的证据表明存在关联(独立性)或分布不同(同质性)。检验不说明方向,也不说明原因。只有数据来自随机化实验时才能下因果结论,因为排除混杂因素的是随机分配,而不是卡方计算。对于调查或其他观察研究,只能说“有关联”,不能说“导致”,并结合情境写出结论。
Worked Example 8.11: homogeneity test with a significant result例题 8.11:结果显著的同质性检验
Use the school-transport data from Topic 11.4: separate random samples of $60$ sophomores and $90$ seniors. Test at $\alpha=0.05$ whether the distribution of usual transport differs between the grades.
- State. $H_0$: the distribution of usual transport to school (bus, car, walk) is the same for sophomores and seniors at this school. $H_a$: the distribution differs.
- Plan. Chi-square test of homogeneity. Random: two separate random samples. 10%: each sample is less than $10\%$ of its grade. All six expected counts are at least $12.8$ (Worked Example 8.7).
- Do. Contributions: sophomores $2.909$, $2.057$, $0.050$; seniors $1.939$, $1.371$, $0.033$. So $\chi^2=8.360$, $\text{df}=(2-1)(3-1)=2$, and the p-value is
χ²cdf($8.360$, 1E99, $2$) $=0.0153$. - Conclude. Because $0.0153<0.05$, we reject $H_0$. There is convincing evidence that the distribution of usual transport to school differs between sophomores and seniors at this school.
- Where? Bus and car carry almost all of the statistic. Bus: $50\%$ of sophomores ($30$ against $22$ expected) but only $27.8\%$ of seniors. Car: $30\%$ of sophomores but $50\%$ of seniors. Walking is close to expected for both ($20\%$ and $22.2\%$).
使用主题 11.4 的学校出行数据:分别随机抽取 $60$ 名高二学生和 $90$ 名高三学生。在 $\alpha=0.05$ 下检验两个年级通常出行方式的分布是否不同。
- 陈述。$H_0$:该校高二与高三学生通常的上学出行方式(公交、汽车、步行)的分布相同。$H_a$:分布不同。
- 计划。卡方同质性检验。随机:两个分别抽取的随机样本。10%:每个样本都不到其年级人数的 $10\%$。六个期望计数都不小于 $12.8$(例题 8.7)。
- 计算。各项贡献:高二 $2.909$、$2.057$、$0.050$;高三 $1.939$、$1.371$、$0.033$。于是 $\chi^2=8.360$,$\text{df}=(2-1)(3-1)=2$,p 值为
χ²cdf($8.360$, 1E99, $2$) $=0.0153$。 - 结论。因为 $0.0153<0.05$,拒绝 $H_0$。有令人信服的证据表明,该校高二与高三学生通常的上学出行方式分布不同。
- 差异在哪里?公交和汽车几乎占了全部统计量。公交:高二学生 $50\%$(观测 $30$,期望 $22$),高三仅 $27.8\%$。汽车:高二 $30\%$,高三 $50\%$。步行两组都接近期望($20\%$ 与 $22.2\%$)。
Worked Example 8.12: homogeneity in an experiment: what can be concluded例题 8.12:实验中的同质性检验:能得出什么结论
An online course randomly assigns $180$ volunteers to three groups of $60$: app reminders, email reminders, or no reminders. The numbers who complete the course are $42$, $33$ and $24$. Test at $\alpha=0.05$. (Illustrative data.)
- State. $H_0$: for volunteers like these, the distribution of completing or not completing is the same under all three reminder methods. $H_a$: the distribution differs for at least one method.
- Plan. Chi-square test of homogeneity (random assignment to three treatments). The completed column total is $99$ and the not-completed total is $81$, so every expected count is $\frac{(60)(99)}{180}=33$ or $\frac{(60)(81)}{180}=27$, all at least $5$.
- Do. Contributions: app $\frac{(42-33)^2}{33}=2.455$ and $\frac{(18-27)^2}{27}=3.000$; email $0$ and $0$; none $2.455$ and $3.000$. So $\chi^2=10.909$, $\text{df}=(3-1)(2-1)=2$, and the p-value is $0.0043$.
- Conclude. Because $0.0043<0.05$, we reject $H_0$. There is convincing evidence that the completion distribution differs among the three reminder methods for volunteers like these. The email group sits exactly on the overall rate of $55\%$; the app group ($70\%$) and the no-reminder group ($40\%$) produce all of the statistic (Figure 8.5).
- Causation? Treatments were randomly assigned, so the difference can be attributed to the reminder method. The volunteers were not randomly selected, so the result applies only to volunteers like these, and the test does not say which method is better by itself.
一门在线课程把 $180$ 名志愿者随机分成三组,每组 $60$ 人:应用提醒、邮件提醒、无提醒。完成课程的人数分别为 $42$、$33$、$24$。在 $\alpha=0.05$ 下检验。(虚构数据。)
- 陈述。$H_0$:对于与这些志愿者相似的人,三种提醒方式下“完成/未完成”的分布相同。$H_a$:至少有一种方式的分布不同。
- 计划。卡方同质性检验(随机分配到三种处理)。完成一列合计为 $99$,未完成合计为 $81$,所以每个期望计数为 $\frac{(60)(99)}{180}=33$ 或 $\frac{(60)(81)}{180}=27$,都不小于 $5$。
- 计算。各项贡献:应用 $\frac{(42-33)^2}{33}=2.455$ 和 $\frac{(18-27)^2}{27}=3.000$;邮件 $0$ 和 $0$;无提醒 $2.455$ 和 $3.000$。于是 $\chi^2=10.909$,$\text{df}=(3-1)(2-1)=2$,p 值为 $0.0043$。
- 结论。因为 $0.0043<0.05$,拒绝 $H_0$。有令人信服的证据表明,对与这些志愿者相似的人,三种提醒方式下的完成情况分布不同。邮件组恰好等于总体完成率 $55\%$;应用组($70\%$)和无提醒组($40\%$)贡献了全部统计量(图 8.5)。
- 因果?处理是随机分配的,所以差异可归因于提醒方式。志愿者不是随机选取的,因此结果只适用于与这些志愿者相似的人;检验本身也不会单独说明哪种方式更好。
Prompt. Use the news-site sample from Worked Example 8.10 (one random sample of $300$ adults). Is there convincing evidence of an association between age group and preferred news source for adults in this city? Use $\alpha=0.05$. (Illustrative data.)
| Part | What a complete answer states |
|---|---|
| Hypotheses | $H_0$: age group and preferred news source are independent for adults in this city. $H_a$: they are associated. |
| Conditions | Random sample; $300$ is under $10\%$ of the adults in the city; expected counts $45, 27, 18 / 60, 36, 24 / 45, 27, 18$ are all at least $5$. |
| Test, statistic, df, p-value | Chi-square test of independence: $\chi^2=32.10$, $\text{df}=(3-1)(3-1)=4$, p-value $=1.8\times 10^{-6}$. |
| Conclusion | Because the p-value is far below $0.05$, we reject $H_0$. There is convincing evidence of an association between age group and preferred news source among adults in this city. |
| Where and why not cause | The largest contributions are adults $55$ and over choosing print ($30$ observed against $18$ expected, $8.0$) and choosing online ($27$ against $45$, $7.2$), and adults $18$ to $34$ choosing online ($63$ against $45$, $7.2$). This is an observational survey, so the result shows an association, not that age causes the preference. |
题目。使用例题 8.10 中新闻网站的样本($300$ 名成年人的一个随机样本)。对该市成年人,是否有令人信服的证据表明年龄组与首选新闻来源有关联?取 $\alpha=0.05$。(虚构数据。)
| 部分 | 完整答案要点 |
|---|---|
| 假设 | $H_0$:该市成年人的年龄组与首选新闻来源相互独立。$H_a$:二者有关联。 |
| 条件 | 随机样本;$300$ 不到该市成年人数的 $10\%$;期望计数 $45, 27, 18 / 60, 36, 24 / 45, 27, 18$ 都不小于 $5$。 |
| 检验、统计量、自由度、p 值 | 卡方独立性检验:$\chi^2=32.10$,$\text{df}=(3-1)(3-1)=4$,p 值 $=1.8\times 10^{-6}$。 |
| 结论 | 因为 p 值远小于 $0.05$,拒绝 $H_0$。有令人信服的证据表明该市成年人的年龄组与首选新闻来源有关联。 |
| 差异在哪里,为何不是因果 | 最大的贡献来自 $55$ 岁及以上选择纸媒(观测 $30$,期望 $18$,贡献 $8.0$)和选择网络($27$ 对 $45$,$7.2$),以及 $18$ 至 $34$ 岁选择网络($63$ 对 $45$,$7.2$)。这是观察性调查,结果只表明有关联,不表明年龄导致了偏好。 |
Following up a significant table对显著的表做后续分析
A small p-value says the distributions differ somewhere; it does not say where. Two follow-ups are allowed. First, rank the cell contributions $\frac{(O-E)^2}{E}$: the cells with the largest values disagree most with $H_0$ and together account for most of $\chi^2$. Second, compare the percentages within each row (for homogeneity, within each group), because percentages describe the pattern in plain words, such as 'a larger share than expected sleep under 6 hours'. The contributions locate the surprise and the percentages describe it. Neither is a separate test, and neither shows cause and effect.
p 值小只说明分布在某处不同,没有说明在哪里。允许做两种后续分析。第一,把单元格贡献 $\frac{(O-E)^2}{E}$ 排序:值最大的单元格与 $H_0$ 分歧最大,合起来占了 $\chi^2$ 的大部分。第二,比较每一行(同质性检验中即每一组)内部的百分比,因为百分比能用平实的话描述模式,例如“睡眠不足 6 小时的比例高于预期”。贡献用来定位令人意外之处,百分比用来描述它。两者都不是单独的检验,也都不能说明因果。
Reporting calculator output如何报告计算器输出
A complete report names the test, states the observed table that was entered, and gives $\chi^2$, the df and the p-value. The calculator stores the expected counts in matrix [B], so use them to state the large-counts check. It does not list contributions, so compute $\frac{(O-E)^2}{E}$ by hand for the cells you cite. A bare line such as 'p = 0.0004' could belong to any test, so label each number with what it is.
完整的报告要写出检验名称,说明输入的观测表,并给出 $\chi^2$、自由度和 p 值。计算器把期望计数存放在矩阵 [B] 中,用它们来说明大计数检验。计算器不列出各单元格的贡献,所以要对你引用的单元格手算 $\frac{(O-E)^2}{E}$。只写一行“p = 0.0004”可能属于任何检验,所以每个数字都要标明它是什么。
Worked Example: locate and describe an association例题:定位并描述关联
Random samples of $100$ students are taken from each of Grades $9$, $10$ and $11$, and each student's usual nightly sleep is recorded as under $6$ hours, $6$ to $8$ hours or over $8$ hours. The counts are $30$, $50$, $20$ for Grade $9$; $45$, $40$, $15$ for Grade $10$; and $20$, $45$, $35$ for Grade $11$. Test at $\alpha=0.05$ and describe where the difference lies. (Illustrative.)
- State. $H_0$: the distribution of nightly sleep category is the same in the three grades. $H_a$: the distribution differs for at least one grade.
- Plan. Chi-square test of homogeneity: three separate random samples, one categorical variable. The column totals are $95$, $135$ and $70$ and the table total is $300$, so the expected counts are $\frac{(100)(95)}{300}=31.67$, $45$ and $23.33$ in every row, all at least $5$.
- Do. Contributions: Grade $9$ gives $0.088$, $0.556$, $0.476$; Grade $10$ gives $5.614$, $0.556$, $2.976$; Grade $11$ gives $4.298$, $0$, $5.833$. Then $\chi^2=20.40$, $\text{df}=(3-1)(3-1)=4$ and the p-value is
χ²cdf($20.40$, 1E99, $4$) $=0.0004$. - Conclude. Because $0.0004<0.05$, reject $H_0$. There is convincing evidence that the distribution of nightly sleep differs among the three grades.
- Where? The two largest contributions are Grade $11$ with over $8$ hours ($35$ observed against $23.33$ expected, $5.833$) and Grade $10$ with under $6$ hours ($45$ against $31.67$, $5.614$). In percentages, $45\%$ of Grade $10$ sleep under $6$ hours compared with $30\%$ of Grade $9$ and $20\%$ of Grade $11$, while $35\%$ of Grade $11$ sleep over $8$ hours compared with $20\%$ and $15\%$.
从 $9$、$10$、$11$ 年级各随机抽取 $100$ 名学生,把每人通常的夜间睡眠记为少于 $6$ 小时、$6$ 至 $8$ 小时或多于 $8$ 小时。$9$ 年级的计数为 $30$、$50$、$20$;$10$ 年级为 $45$、$40$、$15$;$11$ 年级为 $20$、$45$、$35$。在 $\alpha=0.05$ 下检验,并描述差异出现在哪里。(虚构示例。)
- 陈述。$H_0$:三个年级的夜间睡眠类别的分布相同。$H_a$:至少有一个年级的分布不同。
- 计划。卡方同质性检验:三个分别抽取的随机样本,一个分类变量。列合计为 $95$、$135$、$70$,表总计为 $300$,所以每一行的期望计数都是 $\frac{(100)(95)}{300}=31.67$、$45$、$23.33$,均不小于 $5$。
- 计算。各项贡献:$9$ 年级为 $0.088$、$0.556$、$0.476$;$10$ 年级为 $5.614$、$0.556$、$2.976$;$11$ 年级为 $4.298$、$0$、$5.833$。于是 $\chi^2=20.40$,$\text{df}=(3-1)(3-1)=4$,p 值为
χ²cdf($20.40$, 1E99, $4$) $=0.0004$。 - 结论。因为 $0.0004<0.05$,拒绝 $H_0$。有令人信服的证据表明三个年级夜间睡眠的分布不同。
- 差异在哪里?最大的两个贡献是 $11$ 年级睡眠多于 $8$ 小时(观测 $35$,期望 $23.33$,贡献 $5.833$)和 $10$ 年级睡眠少于 $6$ 小时(观测 $45$,期望 $31.67$,贡献 $5.614$)。用百分比表示:$10$ 年级有 $45\%$ 睡眠少于 $6$ 小时,$9$ 年级为 $30\%$,$11$ 年级为 $20\%$;而 $11$ 年级有 $35\%$ 睡眠多于 $8$ 小时,另两个年级分别为 $20\%$ 和 $15\%$。
In the example above a student takes the contribution $5.614$ for the cell 'Grade $10$, under $6$ hours', treats it as a chi-square statistic with $\text{df}=1$, finds a p-value of $0.0178$ and announces a 'significant cell'. A contribution is one piece of a single statistic whose df is $4$, so it has no p-value of its own, and picking the largest cell after seeing the data makes any such p-value misleading. The fix: base the decision on $\chi^2=20.40$ with $\text{df}=4$, and use the contributions only to describe where the data disagree with $H_0$.
在上面的例子中,某学生取单元格“$10$ 年级、少于 $6$ 小时”的贡献 $5.614$,把它当作 $\text{df}=1$ 的卡方统计量,求出 p 值 $0.0178$,宣布这是一个“显著的单元格”。贡献只是一个自由度为 $4$ 的统计量的一部分,它没有自己的 p 值;而且在看过数据后挑出最大的单元格,会使这样的 p 值产生误导。正确做法:以 $\chi^2=20.40$、$\text{df}=4$ 作决定,贡献只用来描述数据在哪里与 $H_0$ 不一致。
Enter only the body of the table in the matrix, never the totals. Write down the test name, $\chi^2$, the df and the p-value, because a bare calculator result without the setup is an incomplete answer. Close with a conclusion that names the population and variables, and use "associated" rather than "causes" unless the study was a randomized experiment.
矩阵中只输入表的主体,不要输入合计。写出检验名称、$\chi^2$、自由度和 p 值,因为只给计算器结果而没有过程是不完整的答案。结论要写明总体与变量,除非研究是随机化实验,否则用“有关联”而不是“导致”。
- Entering the row and column totals into the matrix, which changes the statistic and df.
- Concluding that all groups differ after a rejection; the evidence is only that at least one differs.
- Using the p-value to claim a direction or a cause.
- 把行合计和列合计也输入矩阵,这会改变统计量和自由度。
- 拒绝后断定所有组都不同;证据只说明至少有一组不同。
- 用 p 值来断言方向或因果。
A chi-square test with $\text{df}=2$ gives $\chi^2=3.1$. Find the p-value and state the conclusion at $\alpha=0.05$.一个 $\text{df}=2$ 的卡方检验得到 $\chi^2=3.1$。求 p 值并在 $\alpha=0.05$ 下写出结论。
The p-value is χ²cdf($3.1$, 1E99, $2$) $=0.212$. Because $0.212>0.05$, we fail to reject $H_0$: there is not convincing evidence of a difference or an association.
p 值为 χ²cdf($3.1$, 1E99, $2$) $=0.212$。因为 $0.212>0.05$,不能拒绝 $H_0$:没有令人信服的差异或关联证据。
A survey finds a significant association between region and brand preference (p-value $0.003$). May the report say region causes brand preference?一项调查发现地区与品牌偏好有显著关联(p 值 $0.003$)。报告可以说地区导致了品牌偏好吗?
No. A survey is observational, and a chi-square test shows association only. Other variables could explain it, and the test gives no direction.
不可以。调查是观察研究,卡方检验只能表明关联。可能有其他变量能解释它,而且检验不给出方向。
A cell has $O=36$ and $E=27$. Find its contribution and say whether the count is above or below expectation.某单元格 $O=36$,$E=27$。求它的贡献,并说明该计数高于还是低于期望。
$\frac{(36-27)^2}{27}=3.0$. The observed count is above the expected count.
$\frac{(36-27)^2}{27}=3.0$。观测计数高于期望计数。
Selecting an inference procedure选择推断过程
- Choose among goodness of fit, homogeneity, independence and the $z$ or $t$ procedures from the design and the data type.
- Justify the choice in one sentence that names the design.
- Explain why a chi-square test on a $2\times 2$ table matches a two-proportion $z$ test, and when each is the better tool.
- Recognize when chi-square is not appropriate (means, quantitative data, a one-sided question).
- 根据设计与数据类型,在拟合优度、同质性、独立性以及 $z$ 或 $t$ 过程中做出选择。
- 用一句话说明所选检验并点明设计。
- 说明为什么 $2\times 2$ 表的卡方检验与两比例 $z$ 检验等价,以及各自何时更合适。
- 识别不能用卡方的情形(均值、定量数据、单侧问题)。
Selecting the appropriate inference procedure is a skill of its own. Ask three questions in order. 1. What type of data? Counts in categories point to a chi-square test or a $z$ procedure for proportions; measurements point to $t$ procedures for means or to inference for a slope. 2. How were the data collected? One sample or several separate samples, and how many variables. 3. What is the question? Does one variable match a claimed distribution, is a distribution the same across groups, or are two variables associated? Figure 8.6 summarizes which test to choose.
选择合适的推断过程本身就是一项技能。依次问三个问题。1. 数据是什么类型?类别中的计数对应卡方检验或比例的 $z$ 过程;测量值对应均值的 $t$ 过程或斜率的推断。2. 数据怎样收集?一个样本还是多个独立样本,以及有几个变量。3. 问题是什么?一个变量是否符合给定分布,多个组的分布是否相同,还是两个变量是否有关联?图 8.6 总结了应选哪种检验。
| Situation | Procedure | Degrees of freedom |
|---|---|---|
| One random sample, one categorical variable, claimed distribution | Chi-square goodness-of-fit test | $k-1$ |
| Separate samples or treatment groups, one categorical variable, more than two groups or categories | Chi-square test of homogeneity | $(r-1)(c-1)$ |
| One random sample, two categorical variables | Chi-square test of independence | $(r-1)(c-1)$ |
| One or two proportions, two categories, any direction in $H_a$ | One- or two-proportion $z$ procedure | none |
| Means of quantitative data, or the slope of a regression line | $t$ procedures | see Units 8 to 10 and 12 |
| 情境 | 过程 | 自由度 |
|---|---|---|
| 一个随机样本,一个分类变量,给定分布 | 卡方拟合优度检验 | $k-1$ |
| 分别抽样或处理组,一个分类变量,多于两组或多于两个类别 | 卡方同质性检验 | $(r-1)(c-1)$ |
| 一个随机样本,两个分类变量 | 卡方独立性检验 | $(r-1)(c-1)$ |
| 一个或两个比例,两个类别,$H_a$ 可有任意方向 | 单比例或双比例 $z$ 过程 | 无 |
| 定量数据的均值,或回归直线的斜率 | $t$ 过程 | 见单元 8 至 10 与 12 |
Worked Example 8.13: which procedure? classify five studies例题 8.13:用哪种检验?分类五项研究
Choose the procedure for each study. (Illustrative scenarios.)
- (a) One random sample of $500$ voters is classified by party ($3$ parties) and region ($4$ regions); is there an association? Chi-square test of independence, $\text{df}=(3-1)(4-1)=6$.
- (b) A random sample of $250$ shoppers is classified by payment type (cash, card, mobile), and a company report claims shares of $30\%$, $60\%$ and $10\%$. Chi-square goodness-of-fit test, $\text{df}=3-1=2$, expected counts $75$, $150$, $25$.
- (c) Random samples of $100$ parts from each of $3$ factories are classified as defective or not. Chi-square test of homogeneity ($3\times 2$ table), $\text{df}=2$.
- (d) Random samples of students at two schools report hours of sleep, and we compare the means. Two-sample $t$ test: the data are quantitative, so chi-square does not apply.
- (e) A random sample of $400$ voters is used to test whether the proportion supporting a measure is greater than $0.5$. One-proportion $z$ test: one proportion and a one-sided alternative.
为每项研究选择检验过程。(虚构情境。)
- (a) 对 $500$ 名选民的一个随机样本按政党($3$ 个)和地区($4$ 个)分类;二者有关联吗?卡方独立性检验,$\text{df}=(3-1)(4-1)=6$。
- (b) 对 $250$ 名顾客的随机样本按支付方式(现金、银行卡、移动支付)分类,公司报告声称占比为 $30\%$、$60\%$、$10\%$。卡方拟合优度检验,$\text{df}=3-1=2$,期望计数 $75$、$150$、$25$。
- (c) 各随机抽取 $100$ 个零件,分别来自 $3$ 家工厂,并分类为次品或非次品。卡方同质性检验($3\times 2$ 表),$\text{df}=2$。
- (d) 从两所学校分别随机抽取学生报告睡眠时间,并比较均值。双样本 $t$ 检验:数据是定量的,不能用卡方。
- (e) 用 $400$ 名选民的随机样本检验支持某提案的比例是否大于 $0.5$。单比例 $z$ 检验:一个比例且备择假设为单侧。
Worked Example 8.14: a 2x2 chi-square test and the two-proportion z test agree例题 8.14:2x2 卡方检验与双比例 z 检验结果一致
Two treatments are randomly assigned to $120$ patients each. Improved: $84$ of $120$ on treatment 1 and $66$ of $120$ on treatment 2. (Illustrative data.)
- Chi-square: the improved column total is $150$ and the not-improved total is $90$, so the expected counts are $75$ and $45$ in each row. Contributions are $\frac{(84-75)^2}{75}=1.08$ and $\frac{(36-45)^2}{45}=1.80$ in row 1, and the same in row 2. So $\chi^2=5.76$, $\text{df}=(2-1)(2-1)=1$, p-value $=0.0164$.
- Two-proportion $z$: $\hat p_1=0.70$, $\hat p_2=0.55$, pooled $\hat p=\frac{150}{240}=0.625$, and $SE=\sqrt{0.625(0.375)\left(\frac1{120}+\frac1{120}\right)}=0.0625$. Then $z=\frac{0.70-0.55}{0.0625}=2.4$, and the two-sided p-value is $0.0164$.
- The two agree: $z^2=2.4^2=5.76=\chi^2$, with the same p-value. Use the $z$ procedure if you need a one-sided alternative, the direction of the difference or a confidence interval. The chi-square test only reports that the distributions differ.
两种治疗方法被随机分配给患者,每组 $120$ 人。好转人数:治疗 1 有 $84$ 人(共 $120$ 人),治疗 2 有 $66$ 人(共 $120$ 人)。(虚构数据。)
- 卡方:好转一列合计为 $150$,未好转合计为 $90$,所以每行的期望计数为 $75$ 和 $45$。第一行的贡献为 $\frac{(84-75)^2}{75}=1.08$ 和 $\frac{(36-45)^2}{45}=1.80$,第二行相同。于是 $\chi^2=5.76$,$\text{df}=(2-1)(2-1)=1$,p 值 $=0.0164$。
- 双比例 $z$:$\hat p_1=0.70$,$\hat p_2=0.55$,合并比例 $\hat p=\frac{150}{240}=0.625$,$SE=\sqrt{0.625(0.375)\left(\frac1{120}+\frac1{120}\right)}=0.0625$。于是 $z=\frac{0.70-0.55}{0.0625}=2.4$,双侧 p 值为 $0.0164$。
- 两者一致:$z^2=2.4^2=5.76=\chi^2$,p 值相同。若需要单侧备择假设、差异的方向或置信区间,就用 $z$ 过程。卡方检验只能说明分布不同。
Chi-square or z with two categories两个类别时用卡方还是 z
With one categorical variable that has only two categories, a goodness-of-fit test with $k=2$ and a one-proportion $z$ test with a two-sided alternative are the same test: $\chi^2=z^2$, $\text{df}=1$ and the p-values match. The $z$ test is the better tool when the alternative has a direction, because squaring a chi-square statistic throws the sign away. The chi-square test is the better tool when there are three or more categories or groups, where no single $z$ statistic exists.
当分类变量只有两个类别时,$k=2$ 的拟合优度检验与双侧备择假设的单比例 $z$ 检验是同一个检验:$\chi^2=z^2$,$\text{df}=1$,p 值相同。备择假设有方向时,$z$ 检验是更好的工具,因为卡方统计量的平方把符号丢掉了。有三个或更多类别或组时,卡方检验更合适,因为这时不存在单一的 $z$ 统计量。
Conditions no procedure can repair任何过程都无法弥补的条件
A chi-square test needs independent observations. Data on the same individuals measured twice (before and after a campaign) or on matched pairs break that condition, so a $2\times 2$ table built from them has counted every person twice. Use a paired procedure on the differences instead. The test also needs counts, not percentages or averages, because the size of the sample is part of the evidence: the same percentages from a larger sample give a larger statistic.
卡方检验要求观测相互独立。对同一批个体测量两次(活动前后)或配对数据会破坏这一条件,据此做出的 $2\times 2$ 表把每个人数了两次。应改用对差值的配对过程。检验还需要计数而不是百分比或平均数,因为样本量本身就是证据的一部分:同样的百分比来自更大的样本,统计量就更大。
Worked Example: a two-category test checked against the z test例题:用 z 检验核对两个类别的检验
A club claims that $50\%$ of its members support a new meeting schedule. In a random sample of $200$ members (the club has more than $2000$ members) $118$ support it and $82$ do not. Is there convincing evidence that the proportion differs from $0.5$? Test at $\alpha=0.05$ and then check with a one-proportion $z$ test. (Illustrative.)
- The procedure is a goodness-of-fit test with $k=2$. $H_0$: the proportions of members who support and who do not are $0.5$ and $0.5$. $H_a$: they are not both $0.5$.
- Expected counts are $200(0.5)=100$ and $100$, both at least $5$; the sample is random and $200$ is less than $10\%$ of the members.
- Contributions: $\frac{(118-100)^2}{100}=3.24$ and $\frac{(82-100)^2}{100}=3.24$, so $\chi^2=6.48$ and $\text{df}=2-1=1$. The p-value is
χ²cdf($6.48$, 1E99, $1$) $=0.0109$. - Check with $z$: $\hat p=\frac{118}{200}=0.59$ and $z=\frac{0.59-0.5}{\sqrt{0.5(0.5)/200}}=2.546$. Then $z^2=6.48$, which equals $\chi^2$, and the two-sided p-value is $0.0109$.
- A complete answer states: since $0.0109<0.05$, reject $H_0$; there is convincing evidence that the proportion of club members who support the schedule is not $0.5$. The sample proportion $0.59$ is above $0.5$, but that direction comes from the counts, not from the chi-square test.
- If the club had asked whether more than half support it, the $z$ test would give a one-sided p-value of $\frac{0.0109}{2}\approx 0.0055$, which the chi-square test cannot give.
某俱乐部声称,$50\%$ 的会员支持新的会议时间安排。随机抽取 $200$ 名会员(俱乐部会员超过 $2000$ 人),其中 $118$ 人支持,$82$ 人不支持。是否有令人信服的证据表明支持比例不是 $0.5$?在 $\alpha=0.05$ 下检验,再用单比例 $z$ 检验核对。(虚构示例。)
- 该过程是 $k=2$ 的拟合优度检验。$H_0$:支持与不支持的会员比例分别是 $0.5$ 和 $0.5$。$H_a$:它们不都是 $0.5$。
- 期望计数为 $200(0.5)=100$ 和 $100$,都不小于 $5$;样本是随机的,$200$ 不到会员总数的 $10\%$。
- 各项贡献:$\frac{(118-100)^2}{100}=3.24$ 和 $\frac{(82-100)^2}{100}=3.24$,所以 $\chi^2=6.48$,$\text{df}=2-1=1$。p 值为
χ²cdf($6.48$, 1E99, $1$) $=0.0109$。 - 用 $z$ 核对:$\hat p=\frac{118}{200}=0.59$,$z=\frac{0.59-0.5}{\sqrt{0.5(0.5)/200}}=2.546$。于是 $z^2=6.48$,等于 $\chi^2$,双侧 p 值为 $0.0109$。
- 完整答案要点:因为 $0.0109<0.05$,拒绝 $H_0$;有令人信服的证据表明支持该安排的会员比例不是 $0.5$。样本比例 $0.59$ 高于 $0.5$,但这个方向来自计数,而不是来自卡方检验。
- 如果俱乐部问的是是否有超过一半的人支持,$z$ 检验会给出单侧 p 值 $\frac{0.0109}{2}\approx 0.0055$,这是卡方检验给不出的。
A store surveys $150$ customers before a redesign and the same $150$ customers after it, then builds a $2\times 2$ table of 'satisfied' and 'not satisfied' for 'before' and 'after' and runs a test of homogeneity on $300$ counts. The two columns are not separate samples: each customer appears in both, so the observations are not independent and the large-counts and independence conditions are not met. The fix: because the data are paired, analyze each customer's change (for example with a paired procedure) rather than a chi-square test of homogeneity, and keep chi-square for independent samples or one sample classified twice at the same time.
某商店在改造前调查了 $150$ 名顾客,改造后又调查了同样的 $150$ 名顾客,然后把“改造前”和“改造后”与“满意”和“不满意”做成 $2\times 2$ 表,对 $300$ 个计数做同质性检验。这两列并不是分开的样本:每位顾客在两列中都出现,观测并不相互独立,独立性条件不成立。正确做法:数据是配对的,应分析每位顾客的变化(例如用配对过程),而不是用卡方同质性检验;卡方检验留给独立样本,或同一时刻按两个变量分类的单个样本。
Name the procedure and justify it with the design in one sentence, for example "This is a chi-square test of homogeneity because there are separate random samples from each factory and one categorical variable". A wrong procedure makes every later step invalid as well.
写出过程名称,并用设计在一句话里说明理由,例如“这是卡方同质性检验,因为从每家工厂分别随机抽样,且只有一个分类变量”。选错过程会使后面的每一步都不成立。
- Running a chi-square test on percentages, on means, or on quantitative measurements.
- Using chi-square for a question that needs a direction, such as "is group 1 higher", where a one-sided $z$ test is needed.
- Using goodness of fit when there are two categorical variables, or homogeneity when there is a single sample.
- 对百分比、均值或定量测量值做卡方检验。
- 对需要方向的问题(如“第 1 组是否更高”)使用卡方,这时应使用单侧 $z$ 检验。
- 有两个分类变量时用拟合优度检验,或只有一个样本时用同质性检验。
Each of $300$ randomly sampled employees is classified by department ($4$) and job satisfaction ($3$ levels). Which test, and what is the df?对随机抽取的 $300$ 名员工,按部门($4$ 个)和工作满意度($3$ 档)分类。应做哪种检验?自由度是多少?
A chi-square test of independence (one sample, two categorical variables), $\text{df}=(4-1)(3-1)=6$.
卡方独立性检验(一个样本,两个分类变量),$\text{df}=(4-1)(3-1)=6$。
Researchers want to know whether the proportion improving is higher for group 1 than group 2. Is a chi-square test the best choice?研究者想知道第 1 组好转的比例是否高于第 2 组。卡方检验是最佳选择吗?
No. The question is directional, and the chi-square test cannot be one-sided. Use a one-sided two-proportion $z$ test.
不是。问题带有方向,而卡方检验不能是单侧的。应使用单侧双比例 $z$ 检验。
A $2\times 2$ chi-square test gives $\chi^2=9$. What would $|z|$ and the p-value be for the equivalent two-proportion $z$ test?一个 $2\times 2$ 卡方检验得到 $\chi^2=9$。$|z|$ 与 p 值各是多少?它们对应等价的双比例 $z$ 检验。
$|z|=\sqrt9=3$, and the two-sided p-value is $0.0027$, the same as the chi-square p-value with $\text{df}=1$.
$|z|=\sqrt9=3$,双侧 p 值为 $0.0027$,与 $\text{df}=1$ 的卡方 p 值相同。
Calculator summary计算器汇总
| Task | TI-84 |
|---|---|
| p-value from a statistic | χ²cdf($\chi^2$, 1E99, df) in the DISTR menu |
| Goodness-of-fit test | STAT, right arrow to TESTS, goodness-of-fit test (X2GOF-Test): Observed L1, Expected L2, df |
| Enter a two-way table | 2nd MATRIX, EDIT, [A]: set rows and columns, enter counts only (no totals) |
| Homogeneity or independence test | STAT, right arrow to TESTS, X2-Test: Observed [A], Expected [B]; read $\chi^2$, p-value, df |
| View expected counts | MATRIX, NAMES, [B] after running the test |
| Two proportions, any direction | STAT, right arrow to TESTS, 2-PropZTest |
| 任务 | TI-84 |
|---|---|
| 由统计量求 p 值 | DISTR 菜单中的 χ²cdf($\chi^2$, 1E99, df) |
| 拟合优度检验 | STAT、右箭头到 TESTS、拟合优度检验(X2GOF-Test):Observed L1,Expected L2,df |
| 输入双向表 | 2nd MATRIX、EDIT、[A]:设置行数与列数,只输入计数(不含合计) |
| 同质性或独立性检验 | STAT、右箭头到 TESTS、X2-Test:Observed [A],Expected [B];读取 $\chi^2$、p 值、df |
| 查看期望计数 | 运行检验后,MATRIX、NAMES、[B] |
| 两个比例,任意方向 | STAT、右箭头到 TESTS、2-PropZTest |
Menu labels differ slightly between calculator models and operating systems, so check the screen before entering values.
不同型号和系统的计算器菜单名称略有差异,输入数据前请先核对屏幕。
Flashcards闪卡
Select a card to reveal the answer.
点击卡片查看答案。
Unit quiz单元自测
Answer: B. $\text{df}=k-1=5-1=4$. The df depends on the number of categories, not the sample size.
答案:B。 $\text{df}=k-1=5-1=4$。自由度取决于类别数,而不是样本量。
Answer: B. Multiply the two totals and divide by the table total: $\frac{(40)(70)}{200}=14$.
答案:B。 两个合计相乘再除以表总计:$\frac{(40)(70)}{200}=14$。
Answer: C. $\text{df}=(3-1)(4-1)=6$.
答案:C。 $\text{df}=(3-1)(4-1)=6$。
Answer: B. There are separate random samples and one categorical variable, so the test of homogeneity applies. There is no single claimed distribution, only one sample would suggest independence, and the data are categorical, not quantitative.
答案:B。 这里是分别抽取的随机样本且只有一个分类变量,所以应使用同质性检验。没有单一的给定分布;只有一个样本时才会考虑独立性检验;数据是分类的而不是定量的。
Answer: B. Since $0.0245>0.01$ we fail to reject $H_0$. Failing to reject is not acceptance, and the test never states a direction.
答案:B。 因为 $0.0245>0.01$,不能拒绝 $H_0$。不能拒绝不等于接受,而且检验从不给出方向。
Answer: C. For a $2\times 2$ table $\chi^2=z^2$, so $|z|=\sqrt{5.76}=2.4$.
答案:C。 对 $2\times 2$ 表有 $\chi^2=z^2$,所以 $|z|=\sqrt{5.76}=2.4$。
Answer: B. Each expected count is also multiplied by $3$, and $\frac{(3O-3E)^2}{3E}=3\,\frac{(O-E)^2}{E}$, so the statistic is multiplied by $3$.
答案:B。 每个期望计数也乘以 $3$,并且 $\frac{(3O-3E)^2}{3E}=3\,\frac{(O-E)^2}{E}$,所以统计量变为原来的 $3$ 倍。
Answer: C. Each expected count is $\frac{90}{3}=30$. The contributions are $\frac{(40-30)^2}{30}=3.33$, $0$ and $\frac{(20-30)^2}{30}=3.33$, so $\chi^2=6.67$ and $\text{df}=3-1=2$. The p-value is $0.036$. Dividing by the observed counts gives $7.50$, and leaving out the division gives $200$.
答案:C。 每个期望计数为 $\frac{90}{3}=30$。各项贡献为 $\frac{(40-30)^2}{30}=3.33$、$0$ 和 $\frac{(20-30)^2}{30}=3.33$,所以 $\chi^2=6.67$,$\text{df}=3-1=2$。p 值为 $0.036$。除以观测计数得到 $7.50$,漏掉除法则得到 $200$。
Answer: B. Because $0.003<0.05$ we reject $H_0$, which gives evidence of an association in context. A survey is observational, so it cannot show cause, and the p-value is not the probability that $H_0$ is true.
答案:B。 因为 $0.003<0.05$,拒绝 $H_0$,这给出了结合情境的关联证据。调查是观察性的,不能说明因果;p 值也不是 $H_0$ 为真的概率。
Answer: A. The table total is $30+20=50$, so $E=\frac{(30)(28)}{50}=16.8$. Taking half of the row total ($15$) ignores the column totals, $840$ leaves out the division by the table total, and $11.2$ is the expected count for the second row, first column.
答案:A。 表总计为 $30+20=50$,所以 $E=\frac{(30)(28)}{50}=16.8$。取行合计的一半($15$)忽略了列合计,$840$ 漏掉了除以表总计,而 $11.2$ 是第二行第一列的期望计数。
Answer: D. The ratio has $16$ parts and the second category has $3$ of them, so $E=160\cdot\frac{3}{16}=30$. The value $40$ treats the four categories as equally likely, $53.3$ divides by $3$ instead of $16$, and $10$ is the expected count of the last category.
答案:D。 该比例共 $16$ 份,第二个类别占 $3$ 份,所以 $E=160\cdot\frac{3}{16}=30$。$40$ 把四个类别当成可能性相等,$53.3$ 是除以 $3$ 而不是 $16$,$10$ 则是最后一个类别的期望计数。
χ²cdf($0$, $12$, $4$) and gets $0.9826$. What are the correct p-value and decision at $\alpha=0.05$?Answer: C. The student found the area to the left. The p-value is the right-tail area, χ²cdf($12$, 1E99, $4$) $=0.0174$, and $0.0174<0.05$, so reject $H_0$. Doubling it to $0.0347$ is wrong because the chi-square test has no two-sided version.
χ²cdf($0$, $12$, $4$),得到 $0.9826$。在 $\alpha=0.05$ 下正确的 p 值与决定是什么?答案:C。 该学生求的是左侧面积。p 值是右尾面积,χ²cdf($12$, 1E99, $4$) $=0.0174$,而 $0.0174<0.05$,所以拒绝 $H_0$。把它乘 2 得到 $0.0347$ 是错的,因为卡方检验没有双侧版本。